gpt4 book ai didi

mysql - 如何在同一个表上加入两个选择

转载 作者:行者123 更新时间:2023-11-29 06:51:48 25 4
gpt4 key购买 nike

我有两个选择语句

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com