56,687
社区成员
发帖
与我相关
我的任务
分享
select count(1) FROM Article_tbl where IsRead = 1 and (ArtideImgCount > 0 )
and (select count(1) from `imagelist_tbl` where imagelist_tbl.ArticleID =Article_tbl.ArticleID AND (`imagelist_tbl`.`ImageStatus` = 1) ) >0
--测试数据
if not object_id(N'Tempdb..#T1') is null
drop table #T1
Go
Create table #T1([id] int,[name] nvarchar(22))
Insert #T1
select 1,N'张三' union all
select 2,N'李四' union all
select 3,N'王五' union all
select 4,N'赵六'
GO
if not object_id(N'Tempdb..#T2') is null
drop table #T2
Go
Create table #T2([id] int,[tid] int,[name] nvarchar(23))
Insert #T2
select 1,1,N'测试1' union all
select 2,1,N'测试2' union all
select 3,2,N'测试3'
Go
--测试数据结束
Select COUNT(1) from #T1 WHERE EXISTS(SELECT * FROM #T2 WHERE #T1.id=#T2.tid)
SELECT COUNT(DISTINCT #T1.id) FROM #T1 JOIN #T2 ON #T1.id=#T2.tid
select count(DISTINCT Article_tbl.id) FROM Article_tbl
JOIN `imagelist_tbl` ON imagelist_tbl.ArticleID =Article_tbl.ArticleID
AND (`imagelist_tbl`.`ImageStatus` = 1) where IsRead = 1 and (ArtideImgCount > 0 )