I'm trying to produce a report with the total invoice amount for each customer in the month of December :
| date | customer | invoice amount |
|---|---|---|
| 01/12/2021 | AB1 | 40 |
| 02/11/2021 | AB2 | 60 |
| 12/12/2021 | CE6 | 1000 |
| 31/12/2021 | RF9 | 0.5 |
Could I get any pointers? I'm still fairly new to postgresql.
CodePudding user response:
You should use GROUP BY for your purposes.
SELECT customer, SUM(invoice_amount) as total_invoice_amount
FROM your_table
WHERE EXTRACT(MONTH FROM date) = 12
GROUP BY customer
