Advertisement
Guest User

Untitled

a guest
Jun 18th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. select  
  2.    w_state
  3.   ,i_item_id
  4.   ,sum(case when (cast(d_date as timestamp) < cast ('1998-04-08' as timestamp))
  5.         then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before
  6.   ,sum(case when (cast(d_date as timestamp) >= cast ('1998-04-08' as timestamp))
  7.         then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after
  8.  from
  9.    catalog_sales left outer join catalog_returns on
  10.        (cs_order_number = cr_order_number
  11.         and cs_item_sk = cr_item_sk)
  12.   ,warehouse
  13.   ,item
  14.   ,date_dim
  15.  where
  16.      i_current_price between 0.99 and 1.49
  17.  and i_item_sk          = cs_item_sk
  18.  and cs_warehouse_sk    = w_warehouse_sk
  19.  and cs_sold_data_sk    = d_date_sk
  20.  and cast(d_date as timestamp) between (cast ('1998-04-08' as timestamp) - interval 30 days)
  21.                 and (cast ('1998-04-08' as timestamp) + interval 30 days)
  22.  group by
  23.     w_state,i_item_id
  24.  order by w_state,i_item_id
  25. limit 100;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement