gpt4 book ai didi

Mysql:将三行分组在一起

转载 作者:行者123 更新时间:2023-11-29 07:32:29 26 4
gpt4 key购买 nike

我有三行,如下所示

merchant    col1    col2    col3    col4
Al's 1 0 0 0
Al's 0 2 0 0
Al's 0 0 3 0
Al's 0 0 0 4

我想把它变成:

merchant    col1    col2    col3    col4
Al's 1 2 3 4

当我尝试实现上述目标时,我尝试按商家对其进行分组。当我这样做时:

group by merchant

在查询结束时,我得到这个结果

merchant    col1    col2    col3    col4
Al's 1 0 0 0

所以基本上只有第一行。有什么办法可以完成我所需要的吗?非常感谢

最佳答案

类似这样的事情

select merchant,max(col1),max(col2),max(col3)..
from yourtable
group by merchant

或者如果其他值始终为零,则

select merchant,sum(col1),sum(col2),sum(col3)..
from yourtable
group by merchant

关于Mysql:将三行分组在一起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32124686/

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