query85.sql 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. -- start query 1 in stream 0 using template query85.tpl and seed 622697896
  2. select substr(r_reason_desc,1,20)
  3. ,avg(ws_quantity)
  4. ,avg(wr_refunded_cash)
  5. ,avg(wr_fee)
  6. from web_sales, web_returns, web_page, customer_demographics cd1,
  7. customer_demographics cd2, customer_address, date_dim, reason
  8. where ws_web_page_sk = wp_web_page_sk
  9. and ws_item_sk = wr_item_sk
  10. and ws_order_number = wr_order_number
  11. and ws_sold_date_sk = d_date_sk and d_year = 2001
  12. and cd1.cd_demo_sk = wr_refunded_cdemo_sk
  13. and cd2.cd_demo_sk = wr_returning_cdemo_sk
  14. and ca_address_sk = wr_refunded_addr_sk
  15. and r_reason_sk = wr_reason_sk
  16. and
  17. (
  18. (
  19. cd1.cd_marital_status = 'M'
  20. and
  21. cd1.cd_marital_status = cd2.cd_marital_status
  22. and
  23. cd1.cd_education_status = '4 yr Degree'
  24. and
  25. cd1.cd_education_status = cd2.cd_education_status
  26. and
  27. ws_sales_price between 100.00 and 150.00
  28. )
  29. or
  30. (
  31. cd1.cd_marital_status = 'S'
  32. and
  33. cd1.cd_marital_status = cd2.cd_marital_status
  34. and
  35. cd1.cd_education_status = 'College'
  36. and
  37. cd1.cd_education_status = cd2.cd_education_status
  38. and
  39. ws_sales_price between 50.00 and 100.00
  40. )
  41. or
  42. (
  43. cd1.cd_marital_status = 'D'
  44. and
  45. cd1.cd_marital_status = cd2.cd_marital_status
  46. and
  47. cd1.cd_education_status = 'Secondary'
  48. and
  49. cd1.cd_education_status = cd2.cd_education_status
  50. and
  51. ws_sales_price between 150.00 and 200.00
  52. )
  53. )
  54. and
  55. (
  56. (
  57. ca_country = 'United States'
  58. and
  59. ca_state in ('TX', 'VA', 'CA')
  60. and ws_net_profit between 100 and 200
  61. )
  62. or
  63. (
  64. ca_country = 'United States'
  65. and
  66. ca_state in ('AR', 'NE', 'MO')
  67. and ws_net_profit between 150 and 300
  68. )
  69. or
  70. (
  71. ca_country = 'United States'
  72. and
  73. ca_state in ('IA', 'MS', 'WA')
  74. and ws_net_profit between 50 and 250
  75. )
  76. )
  77. group by r_reason_desc
  78. order by substr(r_reason_desc,1,20)
  79. ,avg(ws_quantity)
  80. ,avg(wr_refunded_cash)
  81. ,avg(wr_fee)
  82. limit 100;
  83. -- end query 1 in stream 0 using template query85.tpl