Select 201905,sum(s.amount)
From sales s
Where greatest(s.effectivedate,s.entrydate)<=20190530 --last day of each month
Group by s.level1;
Can some one let me know the best way to run above query for last 12 months from current month.
S.effectivedate and s.entrydate are numbers.