mysql sum, with row IDs

2020-07-30 04:26发布

问题:

In MySQL I'm trying to sum up a column but retain the row IDs. When I do a sum, the IDs are compressed and the result is

1 | 1500

What I would like is

1,2,3 | 1500

回答1:

SELECT GROUP_CONCAT(id), SUM(value) FROM table



回答2:

SELECT GROUP_CONCAT(id), SUM(column_name) FROM table_name GROUP BY id


标签: mysql sum