SQl query to sum-up amounts by month/year
sql-server
Solution
select year(date) as y, month(date) as m, sum(paid) as p
from table
group by year(date), month(date)
Problem
I have a table "TABLE" like this: ``` Date(datatime) Paid(int) ``` I have multiple "Paid" amounts per month. I would like to sum up the Paid amount per month/year. So far this is what I tried but I get errors in EXTRACT and in MONTH and however I am far to get it done with the years. ``` SELECT EXTRACT(MONTH FROM Period) AS reference_month , SUM(Paid) AS monthly_payments FROM Paid GROUP BY EXTRACT(MONTH FROM Period) ORDER BY EXTRACT(MONTH FROM Period) ``` I am not really handy at this and I would really appreciate some help.