我有三行,如下所示
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/