1
0

query23.sql 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. -- start query 1 in stream 0 using template query23.tpl and seed 2031708268
  2. with frequent_ss_items as
  3. (select substr(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt
  4. from store_sales
  5. ,date_dim
  6. ,item
  7. where ss_sold_date_sk = d_date_sk
  8. and ss_item_sk = i_item_sk
  9. and d_year in (2000,2000+1,2000+2,2000+3)
  10. group by substr(i_item_desc,1,30),i_item_sk,d_date
  11. having count(*) >4),
  12. max_store_sales as
  13. (select max(csales) tpcds_cmax
  14. from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales
  15. from store_sales
  16. ,customer
  17. ,date_dim
  18. where ss_customer_sk = c_customer_sk
  19. and ss_sold_date_sk = d_date_sk
  20. and d_year in (2000,2000+1,2000+2,2000+3)
  21. group by c_customer_sk) x),
  22. best_ss_customer as
  23. (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales
  24. from store_sales
  25. ,customer
  26. where ss_customer_sk = c_customer_sk
  27. group by c_customer_sk
  28. having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select
  29. *
  30. from
  31. max_store_sales))
  32. select sum(sales)
  33. from (select cs_quantity*cs_list_price sales
  34. from catalog_sales
  35. ,date_dim
  36. where d_year = 2000
  37. and d_moy = 3
  38. and cs_sold_date_sk = d_date_sk
  39. and cs_item_sk in (select item_sk from frequent_ss_items)
  40. and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer)
  41. union all
  42. select ws_quantity*ws_list_price sales
  43. from web_sales
  44. ,date_dim
  45. where d_year = 2000
  46. and d_moy = 3
  47. and ws_sold_date_sk = d_date_sk
  48. and ws_item_sk in (select item_sk from frequent_ss_items)
  49. and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) y
  50. limit 100;
  51. with frequent_ss_items as
  52. (select substr(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt
  53. from store_sales
  54. ,date_dim
  55. ,item
  56. where ss_sold_date_sk = d_date_sk
  57. and ss_item_sk = i_item_sk
  58. and d_year in (2000,2000 + 1,2000 + 2,2000 + 3)
  59. group by substr(i_item_desc,1,30),i_item_sk,d_date
  60. having count(*) >4),
  61. max_store_sales as
  62. (select max(csales) tpcds_cmax
  63. from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales
  64. from store_sales
  65. ,customer
  66. ,date_dim
  67. where ss_customer_sk = c_customer_sk
  68. and ss_sold_date_sk = d_date_sk
  69. and d_year in (2000,2000+1,2000+2,2000+3)
  70. group by c_customer_sk) x),
  71. best_ss_customer as
  72. (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales
  73. from store_sales
  74. ,customer
  75. where ss_customer_sk = c_customer_sk
  76. group by c_customer_sk
  77. having sum(ss_quantity*ss_sales_price) > (95/100.0) * (select
  78. *
  79. from max_store_sales))
  80. select c_last_name,c_first_name,sales
  81. from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales
  82. from catalog_sales
  83. ,customer
  84. ,date_dim
  85. where d_year = 2000
  86. and d_moy = 3
  87. and cs_sold_date_sk = d_date_sk
  88. and cs_item_sk in (select item_sk from frequent_ss_items)
  89. and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer)
  90. and cs_bill_customer_sk = c_customer_sk
  91. group by c_last_name,c_first_name
  92. union all
  93. select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales
  94. from web_sales
  95. ,customer
  96. ,date_dim
  97. where d_year = 2000
  98. and d_moy = 3
  99. and ws_sold_date_sk = d_date_sk
  100. and ws_item_sk in (select item_sk from frequent_ss_items)
  101. and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)
  102. and ws_bill_customer_sk = c_customer_sk
  103. group by c_last_name,c_first_name) y
  104. order by c_last_name,c_first_name,sales
  105. limit 100;
  106. -- end query 1 in stream 0 using template query23.tpl