34

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
kuslahne
  • 720
  • 4
  • 10
  • 21

1 Answers1

59
SELECT id, SUM(amount) AS amount
FROM yourtable
GROUP BY id
Marc B
  • 356,200
  • 43
  • 426
  • 500