我被困在这里。我在Postgres有这样的行:
id amount
a 5000
a 1500
a 500
b 2000
b 1000
c 4000
sql语法如何得到这样的结果?
id amount
a 7000
b 3000
c 4000
答案 0 :(得分:37)
SELECT id, SUM(amount) AS amount
FROM yourtable
GROUP BY id