Skip to content
Advertisement

I need help writing a query that shows the amount of orders for each month of the year and also the cumulative amount each year

I am so close to answering this question, but can’t figure out the final bits. I am using the AdventureWorks2019 database.

My code is:

I cant figure out how to order the ‘over’ part of the query. I know it needs to be “rows between unbounded preceding and current row”, but because MonthlySales is sum(totaldue), adding it to another SUM() probably messes it up.

Honestly this question is pretty tough, and I gave it my best. Thank you for your help!

Advertisement

Answer

Please check and it’ll return desired output.

Also Check data from https://dbfiddle.uk/?rdbms=sqlserver_2019&sample=adventureworks&fiddle=e6cd2ba8114bd1d86b8c61b1453cafcf

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement