select tblog_TblogID from GK_Tblog where tblog_Name= and tblog_SourceID= ; 只有一条记录 ,假如结果为 2
select tmsg_ID from GK_TblogMsg where tmsg_TblogID = 2; 有多条记录 ,假如结果为1, 2, 3
对于上面的结果集,每一个结果:
select count(cmt_ID) from GK_Comment where cmt_MsgID = 1;
select count(cmt_ID) from GK_Comment where cmt_MsgID = 2;
select count(cmt_ID) from GK_Comment where cmt_MsgID = 3;把上面三条语句的执行结果相加,就是我想要的结果
可不可以写一个嵌套的查询实现
我不想做很多次查询
就想写一个sql语句完成,嵌套能否实现
感激不尽
select tmsg_ID from GK_TblogMsg where tmsg_TblogID = 2; 有多条记录 ,假如结果为1, 2, 3
对于上面的结果集,每一个结果:
select count(cmt_ID) from GK_Comment where cmt_MsgID = 1;
select count(cmt_ID) from GK_Comment where cmt_MsgID = 2;
select count(cmt_ID) from GK_Comment where cmt_MsgID = 3;把上面三条语句的执行结果相加,就是我想要的结果
可不可以写一个嵌套的查询实现
我不想做很多次查询
就想写一个sql语句完成,嵌套能否实现
感激不尽
from
(
select count(cmt_ID) as num from GK_Comment where cmt_MsgID = 1
union all
select count(cmt_ID) as num from GK_Comment where cmt_MsgID = 2
union all
select count(cmt_ID) as num from GK_Comment where cmt_MsgID = 3
)T
from GK_Comment
where cmt_MsgID in(select tblog_TblogID
from GK_Tblog where tblog_Name= and tblog_SourceID= )
from GK_Comment
where cmt_MsgID in(select tmsg_ID
from GK_TblogMsg
where tmsg_TblogID in (select tblog_TblogID
from GK_Tblog
where tblog_Name= and tblog_SourceID= );
select tmsg_ID from GK_Tblog a
inner join GK_TblogMsg b
on a.tblog_TblogID=b.tmsg_TblogID
where tblog_Name= and tblog_SourceID= ) d
on d.cmt__MsgID=c.tmsg_ID