有我的SQL数据:
code name total --------------- 3 Sprite 2400 17 Coke 1500 6 Dew 1000 17 Coke 3000 6 Dew 2000
但是代码和名称具有重复的值,我想对每个重复的字段求和。像这样的东西:
code name total --------------- 3 Sprite 2400 17 Coke 4500 6 Dew 3000
我怎样才能在sql中做到这一点?
SELECT code, name, sum(total) AS total FROM table GROUP BY code, name