Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
542 views
in Technique[技术] by (71.8m points)

sql - how to group by and return sum row in Postgres

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
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
SELECT id, SUM(amount) AS amount
FROM yourtable
GROUP BY id

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...