我有两个选择语句
Select author_id, count(text) from posts group by author_id
select author_id, count(text) from posts where postcounter =1 group by author_id
有没有办法在一个查询中合并这两个语句?结果的长度不同,因此需要在第二个结果集中插入一些0。
非常感谢您的帮助
最好的问候, 西蒙妮
最佳答案
您应该能够在单个查询中使用:
Select author_id,
count(text) TextCount,
count(case when postcounter=1 then text end) PostCount
from posts
group by author_id
关于mysql - 如何在同一个表上加入两个选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14904398/