Sum values from Duplicated rows

2019-08-02 07:33发布

问题:

There's my sql data:

code name total
---------------
3   Sprite 2400
17  Coke   1500
6   Dew    1000
17  Coke   3000
6   Dew    2000

But code and name has duplicated values and I want to sum total from each duplicated field. Something like this:

code name total
---------------
3   Sprite 2400
17  Coke   4500
6   Dew    3000

How could I do that in sql?

回答1:

SELECT code, name, sum(total) AS total FROM table GROUP BY code, name