Steven Winston
Steven Winston

Reputation: 102

How to aggregate Postgres table rows

I have a table constructed like this :

Date  | Account  | Total
1     | A        | 1000
3     | A        | 1000
4     | A        | 200
5     | A        | 3000
2     | B        | 100
3     | B        | 2000
4     | C        | 500  

I'd like to query this table to get a result like this :

Date  | Total
1     | 1000
2     | 100
3     | 3000
4     | 700
5     | 3000

Basically, I don't care about the account but want to sum the total per date

I've been going around in circles trying to do this super simpple task! Can someone please help me? hanks! Thank you very much.

Upvotes: 0

Views: 32

Answers (1)

Josh Kupershmidt
Josh Kupershmidt

Reputation: 2710

You are looking for GROUP BY with an aggregate function: SUM. Something like:

SELECT date, SUM(total)
FROM your_table_name
GROUP BY date
ORDER BY date;

Upvotes: 2

Related Questions