gpt4 book ai didi

mysql - MySQL中将n条记录合并为一条记录

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

我有n条记录如下:

###Date Rank1 Rank2 Rank3 Rank4 Rank5 Rank6 Rank7  
10-01-2015 1 0 0 0 0 0 0
10-01-2015 0 1 0 0 0 0 0
10-01-2015 0 0 1 0 0 0 0
10-01-2015 0 0 0 1 0 0 0
10-01-2015 0 0 0 0 1 0 0
10-01-2015 0 0 0 0 0 1 0
10-01-2015 0 0 0 0 0 0 1

我想要的输出是

### Date Rank1 Rank2 Rank3 Rank4 Rank5 Rank6 Rank7  
10-01-2015 1 1 1 1 1 1 1

有什么办法可以实现这一点吗?

最佳答案

您需要sum()group by

select
Date,
sum(Rank1) as Rank1,
sum(Rank2) as Rank2,
sum(Rank3) as Rank3,
sum(Rank4) as Rank4,
sum(Rank5) as Rank5,
sum(Rank6) as Rank6,
sum(Rank7) as Rank7
from table_name
group by Date

关于mysql - MySQL中将n条记录合并为一条记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29554717/

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