Run sql query multiple time by changing filter condition

  1. Sainath007

    Sainath007 Starter

    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    10
    Location:
    Canada
    Hi Team,
    Can some one help i fixing my query?

    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? And last 12 months would be moving monts. Current month-1.

    My aggrigated sum is <= 201905 and it would be something like " start of 1999 year to 201905.
    1999 to 201906
    1999 to 201907
    1999 to 201908
    1999 to 201909
    1999 to 201910
    Current month is nov 201911.

    My results should look like:
    201905 sum 1000
    201906 sum 3000
    201907 sum 45000
    201908 sum 5000
    201909 sum 1000
    201910 sum 1111