How can l group row data by date using window function?

36 Views Asked by At

In my code below the row data are not grouping into month by month name. I want to group row data of the same month.

Date Revenue
2023-03-01 500
2023-03-29 300
2023-04-15 600
2023-05-11 300
2023-05-23 600
2023-05-31 500
SELECT  
    DATENAME(month, OrderDate) as Month,
        Sum(Amount) as revenue,
        Amount - LAG (Amount) OVER (ORDER BY OrderDate ASC) AS Revenue_growth       
FROM OrderDetail
Group by OrderDate

Expected output

Date Revenue Revenue_growth
March 800 0
April 600 -200
May 1400 800
0

There are 0 best solutions below