
Jeremy D. answered 04/11/24
Fortune 30 Principal Data Engineer
Mallorie -
Lets take a look at what dates are output by each function in your solution step by step starting from the inner most function.
4/30/24
Go back 1 month to 3/30/24
Go back 1 month to 2/29/24
Add 0 years to 2/29/24
Get the year (2024)
Go to the first day of the year, 1/1/24
Go back one day to get to prior year, 12/31/23
With no changes, this would still be accurate 11 months out of the year
What will happen during the month of February:
2/1/24
Go back 1 month to 1/1/24
Go back 1 month to 12/1/23
Add 0 years to 12/1/23
Get the year (2023)
Go to the first day of the year, 1/1/23
Go back one day to get to prior year, 12/31/22
With the dates laid out this way, I hope you're able to see what functions can be removed as unnecessary as well as how you'd solve for dates in February.
I would also encourage you to review your where clause, particularly ensuring you understand the difference between "x = null" and "x is null", and the benefits of using parenthesis to help contain your logical operators and their precedence.
Hope this helps.