gpt4 book ai didi

mysql - 如何在 mysql 中使用 group by 对列求和?

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

------------------------------------
Item | Box
------------------------------------
10 | 25
------------------------------------
12 | 50
------------------------------------
3 | 25
------------------------------------
4 | 30
------------------------------------
6 | 50
------------------------------------

输出应该是

[25] => 13   , [50] => 18, [30] => 4

我正在使用以下查询,但我得到了结果

  select sum(item) as qt  from table group by box

请帮我解决我的问题

最佳答案

试试这个:

SELECT sum(item) as qt, box
FROM tablename
GROUP BY box
ORDER BY qt

关于mysql - 如何在 mysql 中使用 group by 对列求和?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41060837/

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