I'm trying to create a query to get the total amount
for every month in the last 6 months.
The idea is something like:
Select
sum(amount) as Total, data
From
myTable
Where
date /* How can I filer by month? */
Group By
/* Group by each month */
Sample data
create table mytable ( Order_date date, Amount float);
insert into mytable values('2021-02-13',24.15);
insert into mytable values('2021-02-13',12.00 );
insert into mytable values('2021-02-16',14.12 );
insert into mytable values('2021-03-02',17.01 );
insert into mytable values('2021-03-14',18.25 );
insert into mytable values('2021-4-1',19.24 );
Amount is decimal and date is date time field.
Desired output:
Total | month |
---|---|
50.269999504089355 | 2021 February |
17.010000228881836 | 2021 March |
Is it possible to create this with only one query?