how to group by and return sum row in Postgres

放肆的年华 提交于 2019-12-03 23:33:14

问题


I am stuck here. I have row in Postgres like this:

id      amount
a       5000
a       1500
a       500
b       2000
b       1000
c       4000

How is the sql syntax to get result like this?

id      amount
a       7000
b       3000
c       4000

回答1:


SELECT id, SUM(amount) AS amount
FROM yourtable
GROUP BY id


来源:https://stackoverflow.com/questions/8004655/how-to-group-by-and-return-sum-row-in-postgres

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!