last 6 months total

Database
Fan

last 6 months total

Hi All,

 

I have to calculate total quantity sold for last 6 months. For example in case of January 2018 , I have to calculate told quantity sold from July - Dec 2017. This total should be grouped by primary key. 

 

Thanks

 

Primary KeyDateqty last 6 months quantity sold
11-Oct40
11-Nov104
15-Dec2014
11-Jan334
11-Sep880
1 REPLY
Junior Contributor

Re: last 6 months total

You can calculate the range using ADD_MONTHS plus TRUNC:

WHERE datecole BETWEEN Trunc(Add_Months(Current_Date, -6), 'mon')
                   AND Trunc(Current_Date, 'mon') -1