Advertisement
Guest User

Untitled

a guest
Nov 18th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 0.82 KB | None | 0 0
  1.     FUNCTION DWREPORT RETURN t_report IS
  2.     v_report t_report;
  3.     BEGIN
  4.         SELECT * BULK COLLECT INTO v_report
  5.         FROM (
  6.             SELECT
  7.                 c.country,
  8.                
  9.                 CASE GROUPING(d.calenderyear)
  10.                   WHEN 0 THEN TO_CHAR(d.calenderyear)
  11.                   ELSE 'TOTAL'
  12.                 END calenderyear,
  13.                 SUM(f.amount) AS amount
  14.               FROM dwfactsales  f
  15.                 JOIN dwdimcustomer c ON c.customerkey = f.customerkey
  16.                 JOIN dwdimdate d ON d.datekey = f.datekey
  17.             GROUP BY c.country, ROLLUP(d.calenderyear)
  18.             )
  19.             PIVOT (SUM(amount) FOR (calenderyear) IN (2009, 2010, 2011, 2012, 2013, 2014, 'TOTAL' AS TOTAL))
  20.         ORDER BY country;
  21.        
  22.         RETURN v_report;
  23.     END DWREPORT;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement