1
0

query80.sql 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. -- start query 1 in stream 0 using template query80.tpl and seed 1819994127
  2. with ssr as
  3. (select s_store_id as store_id,
  4. sum(ss_ext_sales_price) as sales,
  5. sum(coalesce(sr_return_amt, 0)) as returns,
  6. sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit
  7. from store_sales left outer join store_returns on
  8. (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number),
  9. date_dim,
  10. store,
  11. item,
  12. promotion
  13. where ss_sold_date_sk = d_date_sk
  14. and d_date between cast('2002-08-06' as date)
  15. and (cast('2002-08-06' as date) + 30 days)
  16. and ss_store_sk = s_store_sk
  17. and ss_item_sk = i_item_sk
  18. and i_current_price > 50
  19. and ss_promo_sk = p_promo_sk
  20. and p_channel_tv = 'N'
  21. group by s_store_id)
  22. ,
  23. csr as
  24. (select cp_catalog_page_id as catalog_page_id,
  25. sum(cs_ext_sales_price) as sales,
  26. sum(coalesce(cr_return_amount, 0)) as returns,
  27. sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit
  28. from catalog_sales left outer join catalog_returns on
  29. (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number),
  30. date_dim,
  31. catalog_page,
  32. item,
  33. promotion
  34. where cs_sold_date_sk = d_date_sk
  35. and d_date between cast('2002-08-06' as date)
  36. and (cast('2002-08-06' as date) + 30 days)
  37. and cs_catalog_page_sk = cp_catalog_page_sk
  38. and cs_item_sk = i_item_sk
  39. and i_current_price > 50
  40. and cs_promo_sk = p_promo_sk
  41. and p_channel_tv = 'N'
  42. group by cp_catalog_page_id)
  43. ,
  44. wsr as
  45. (select web_site_id,
  46. sum(ws_ext_sales_price) as sales,
  47. sum(coalesce(wr_return_amt, 0)) as returns,
  48. sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit
  49. from web_sales left outer join web_returns on
  50. (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number),
  51. date_dim,
  52. web_site,
  53. item,
  54. promotion
  55. where ws_sold_date_sk = d_date_sk
  56. and d_date between cast('2002-08-06' as date)
  57. and (cast('2002-08-06' as date) + 30 days)
  58. and ws_web_site_sk = web_site_sk
  59. and ws_item_sk = i_item_sk
  60. and i_current_price > 50
  61. and ws_promo_sk = p_promo_sk
  62. and p_channel_tv = 'N'
  63. group by web_site_id)
  64. select channel
  65. , id
  66. , sum(sales) as sales
  67. , sum(returns) as returns
  68. , sum(profit) as profit
  69. from
  70. (select 'store channel' as channel
  71. , 'store' || store_id as id
  72. , sales
  73. , returns
  74. , profit
  75. from ssr
  76. union all
  77. select 'catalog channel' as channel
  78. , 'catalog_page' || catalog_page_id as id
  79. , sales
  80. , returns
  81. , profit
  82. from csr
  83. union all
  84. select 'web channel' as channel
  85. , 'web_site' || web_site_id as id
  86. , sales
  87. , returns
  88. , profit
  89. from wsr
  90. ) x
  91. group by rollup (channel, id)
  92. order by channel
  93. ,id
  94. limit 100;
  95. -- end query 1 in stream 0 using template query80.tpl