Listing 4: Finding Top Three-Month Periods
select * from

  (select FIRST_VALUE(to_char(month,'YYYY-MON')) 
  over (order by month range interval '2' month preceding) 
  as start_month,
  LAST_VALUE(to_char(month,'YYYY-MON')) 

  over (order by month range interval '2' month preceding) 
  as end_month,
  SUM(monthly_sales) over (order by month range interval '2' month preceding)
  as three_month_sales from 
    (select trunc(trans_date, 'MM') as month, sum(sales_amt) 

    as monthly_sales
    from sales group by trunc(trans_date, 'MM')))
where three_month_sales > 10000000
order by to_date(start_month, 'YYYY-MON');

START_MONTH               END_MONTH                 THREE_MONTH_SALES

------------------        ---------------           ----------------------------
1999-APR                  1999-JUN                  10107234
2000-MAY                  2000-JUL                  11213478
2000-JUN                  2000-AUG                  10987251
2000-SEP                  2000-NOV                  11334987




E-mail this page
Printer View Printer View
Oracle Is The Information Company About Oracle | Oracle RSS Feeds | Careers | Contact Us | Site Maps | Legal Notices | Terms of Use | Privacy