Advertisement
Guest User

Untitled

a guest
Dec 18th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 0.83 KB | None | 0 0
  1. --CREATE OR REPLACE VIEW cv7_cum_sum(channel_desc, calendar_month_name, calendar_year, amount_sold, cum_sum) AS
  2. SELECT  
  3.   channel_desc,
  4.   calendar_month_name,
  5.   calendar_year,
  6.   amount_sold,
  7.   SUM(amount_sold) OVER (PARTITION BY channel_desc, calendar_year ORDER BY     to_date(calendar_month_name, 'mm', 'NLS_DATE_LANGUAGE=ENGLISH')   ) AS cum_sum
  8. FROM(
  9. SELECT
  10.   channel_desc,
  11.   calendar_month_name,
  12.    calendar_year ,
  13.   SUM(amount_sold) AS amount_sold
  14. FROM
  15.   sh.sales JOIN sh.customers USING(cust_id)
  16.   JOIN sh.countries USING(country_id)
  17.   JOIN sh.times USING(time_id)
  18.   JOIN sh.channels USING(channel_id)
  19.   JOIN sh.promotions USING(promo_id)
  20.   JOIN sh.products USING(prod_id)
  21. WHERE
  22.   TIME_ID  BETWEEN '01.01.2000' AND '31.12.2001'
  23.   GROUP BY channel_desc, calendar_month_name, calendar_year
  24.   )
  25.  ORDER BY calendar_year;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement