mysql 如何同时查询多个 count

mysql 如何同时查询多个 count,第1张

select count(commentId ),commentId from ( select * from t_like where commentId in ('1','2','3','8','10') and status = 1 ) group by commentId

不知道这样可不可以实现你要

第一种

SELECT (count(*) FROM `bbs_thread` WHERE uid = 7) AS mythreads, (COUNT(*) FROM bbs_post WHERE uid = 7) AS myposts

第二种

SELECT (count(*) FROM `bbs_thread` WHERE uid = 7) AS mythreads, COUNT(*) AS myposts FROM bbs_post WHERE uid = 7

userid在两个表中都应该是唯一的吧,你group by是什么意思呀?

如果需要获得结果的行数,可以使用select count(*) from table1 a,table2 b where a.userid=b.userid.


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/8685528.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-19
下一篇 2023-04-19

发表评论

登录后才能评论

评论列表(0条)

保存