Skip to content
Advertisement

HOW TO CHECK CONDITIONS FOR PREVIOUS MONTH

My table is like

I am trying to get customer_ids where they didn’t do any transactions previous month and made transactions with at least 2 transaction_type at this_month.While doing this I am converting rundate to MM-YYYY format. What I’ve done for getting previous month and this month on MM-YYY format is :

and this is what i got:

But the problem is I couldn’t figure how to check my conditions for both PREV_MONT_YEAR AND MONTH_YEAR at the same time

Advertisement

Answer

You can use window functions: You can aggregate by month and use window functions:

Note: This truncates the date to the first day of the month. I prefer working with dates rather than strings. Of course, you can use to_char(runmonth, 'YYYY-MM') if you prefer strings.

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