gpt4 book ai didi

Mysql:在group by中添加条件

转载 作者:行者123 更新时间:2023-11-30 00:36:21 24 4
gpt4 key购买 nike

通过在查询中使用group by source子句,我得到以下结果。

Source  No_of_users
1 2
2 7
3 3
4 34
5 21

如何对源的某些值进行分组,即输出,例如:

Source   No_of_users
1+2 9
3+5 24
4 34

需要建议。

最佳答案

是的,像这样的联合:

SELECT SUM(no_of_users) AS some_sum from some_table where source in (1,2,3)
UNION
SELECT SUM(no_of_users) AS some_sum from some_table where source in (4,5,6)
UNION
SELECT SUM(no_of_users) AS some_sum from some_table where source in (6,7,8)

关于Mysql:在group by中添加条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22145549/

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