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语句完成,嵌套能否实现
感激不尽
解决方案 »
- MySQL乱码问题 快把我整疯了
- SQL优化 ~~ 出现Using temporary; Using filesort
- MYSQL中身份证号怎么确认出生日期和年龄?
- ERROR 1044 (42000): Access denied for user 'root'@'192.168.0.3' to database 'rfc
- 我第一次来提问哦,希望各位帮帮忙,谁能帮帮我,告诉我C#和JSP如何连接mysql?谢谢了
- 怎样恢复data目录中的mysql数据库?
- mysql里有password这个函数?
- 紧急求救:用mysql-front突然出现漏斗型的等待???(在线等,谢谢,以后补分)
- mysql 如何自定义聚集函数
- 内连接中,是不是等值连接用得最多,自然连接和不等连接用的很少?
- 急!MYSQL无法创建表,报错代码121,库中没有任何外键。
- 恳求,mysql查找父节点下统计所有子节点id
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