Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- FUNCTION DWREPORT RETURN t_report IS
- v_report t_report;
- BEGIN
- SELECT * BULK COLLECT INTO v_report
- FROM (
- SELECT
- c.country,
- CASE GROUPING(d.calenderyear)
- WHEN 0 THEN TO_CHAR(d.calenderyear)
- ELSE 'TOTAL'
- END calenderyear,
- SUM(f.amount) AS amount
- FROM dwfactsales f
- JOIN dwdimcustomer c ON c.customerkey = f.customerkey
- JOIN dwdimdate d ON d.datekey = f.datekey
- GROUP BY c.country, ROLLUP(d.calenderyear)
- )
- PIVOT (SUM(amount) FOR (calenderyear) IN (2009, 2010, 2011, 2012, 2013, 2014, 'TOTAL' AS TOTAL))
- ORDER BY country;
- RETURN v_report;
- END DWREPORT;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement