Skip to Main Content

MySQl Count aggregation until last month vs current month

User_MS2CUMay 7 2022 — edited May 8 2022

change in count aggregation.xlsx (11.43 KB)
Hello,
I'm attaching a sample data by year/month/quantity. What I need to show is "Quantity Change". The calculation that need to do is:
"Quantity Change" = sum(quantity) until last month - sum(quantity) until current month
Here is what I need to show if I'm running this query today (current month is 5):
Quantity_Change
8
if current month is 4 then:
Quantity_Change
21
and so on... I've added the expected "Quantity_Change" column with some helpful columns to do the calculation. btw, need to find the current system date now() or current_date to find the previous month.

Any help and support is really appreciated.
Thanks

Comments
Post Details
Added on May 7 2022
0 comments
64 views