In this setup, the query is grouped by quarter and the Ratio_To_Report computes the quarterly sales to yearly sales totals ratio (37000/183500 = 0.20163 for quarter one, similarly for two and so on, as shown in query output ). Sames as the month/year ratio computation, there is no PARTITION BY clause -
OVER(PARTITION BY )
 ROUND(RATIO_TO_REPORT(SUM(q_sum.sales))
         OVER(),6)*100 "QUARTERLY_%"

resulting in Ratio_To_Report function computed for the complete result set of the query. Next example explains the use of PARTITION BY clause for a dataset consisting of full and partial year .
   
Ratio_To_Report (Quarter/Yearly Total)
SELECT
 q_sum.qtr  quarter,
 SUM(q_sum.sales) qtr_sales,
 SUM(SUM(q_sum.sales)) OVER() yearly_total,
 ROUND(RATIO_TO_REPORT(SUM(q_sum.sales))
         OVER(),6)*100 "QUARTERLY_%"
FROM 
(SELECT  TO_NUMBER(SUBSTR(q_dw.year_id,5)) month_id,
  NTILE(4) OVER(ORDER BY 
                 TO_NUMBER(SUBSTR(q_dw.year_id,5))) qtr,
  SUM(sales) sales
 FROM
   (SELECT 201201 year_id, 11000  sales FROM DUAL UNION
    SELECT 201202 year_id, 12000  sales FROM DUAL UNION
    SELECT 201203 year_id, 14000  sales FROM DUAL UNION
    SELECT 201204 year_id, 16000  sales FROM DUAL UNION
    SELECT 201205 year_id, 15000  sales FROM DUAL UNION
    SELECT 201206 year_id, 18000  sales FROM DUAL UNION
    SELECT 201207 year_id, 19500  sales FROM DUAL UNION
    SELECT 201208 year_id, 17000  sales FROM DUAL UNION
    SELECT 201209 year_id, 16000  sales FROM DUAL UNION
    SELECT 201210 year_id, 16500  sales FROM DUAL UNION
    SELECT 201211 year_id, 13000  sales FROM DUAL UNION
    SELECT 201212 year_id, 15500  sales FROM DUAL
   ) q_dw
 GROUP BY  TO_NUMBER(SUBSTR(q_dw.year_id,5))
) q_sum
GROUP BY q_sum.qtr;
-- Above query output -> Quarter/Year Ratio

Oracle registered trademark of Oracle Corporation.

Last revised on: April 12, 2013

  77485