q85.sql 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. --!syntax_pg
  2. --TPC-DS Q85
  3. -- start query 1 in stream 0 using template ../query_templates/query85.tpl
  4. select substr(r_reason_desc,1,20) reason
  5. ,avg(ws_quantity) avg_ws_q
  6. ,avg(wr_refunded_cash) avg_wr_r
  7. ,avg(wr_fee) avg_wr_f
  8. from plato.web_sales, plato.web_returns, plato.web_page, plato.customer_demographics cd1,
  9. plato.customer_demographics cd2, plato.customer_address, plato.date_dim, plato.reason
  10. where ws_web_page_sk = wp_web_page_sk
  11. and ws_item_sk = wr_item_sk
  12. and ws_order_number = wr_order_number
  13. and ws_sold_date_sk = d_date_sk and d_year = 1998
  14. and cd1.cd_demo_sk = wr_refunded_cdemo_sk
  15. and cd2.cd_demo_sk = wr_returning_cdemo_sk
  16. and ca_address_sk = wr_refunded_addr_sk
  17. and r_reason_sk = wr_reason_sk
  18. and
  19. (
  20. (
  21. cd1.cd_marital_status = 'M'
  22. and
  23. cd1.cd_marital_status = cd2.cd_marital_status
  24. and
  25. cd1.cd_education_status = '4 yr Degree'
  26. and
  27. cd1.cd_education_status = cd2.cd_education_status
  28. and
  29. ws_sales_price between 100.00::numeric and 150.00::numeric
  30. )
  31. or
  32. (
  33. cd1.cd_marital_status = 'D'
  34. and
  35. cd1.cd_marital_status = cd2.cd_marital_status
  36. and
  37. cd1.cd_education_status = 'Primary'
  38. and
  39. cd1.cd_education_status = cd2.cd_education_status
  40. and
  41. ws_sales_price between 50.00::numeric and 100.00::numeric
  42. )
  43. or
  44. (
  45. cd1.cd_marital_status = 'U'
  46. and
  47. cd1.cd_marital_status = cd2.cd_marital_status
  48. and
  49. cd1.cd_education_status = 'Advanced Degree'
  50. and
  51. cd1.cd_education_status = cd2.cd_education_status
  52. and
  53. ws_sales_price between 150.00::numeric and 200.00::numeric
  54. )
  55. )
  56. and
  57. (
  58. (
  59. ca_country = 'United States'
  60. and
  61. ca_state in ('KY', 'GA', 'NM')
  62. and ws_net_profit between 100::numeric and 200::numeric
  63. )
  64. or
  65. (
  66. ca_country = 'United States'
  67. and
  68. ca_state in ('MT', 'OR', 'IN')
  69. and ws_net_profit between 150::numeric and 300::numeric
  70. )
  71. or
  72. (
  73. ca_country = 'United States'
  74. and
  75. ca_state in ('WI', 'MO', 'WV')
  76. and ws_net_profit between 50::numeric and 250::numeric
  77. )
  78. )
  79. group by r_reason_desc
  80. order by substr(r_reason_desc,1,20)
  81. ,avg(ws_quantity)
  82. ,avg(wr_refunded_cash)
  83. ,avg(wr_fee)
  84. limit 100;
  85. -- end query 1 in stream 0 using template ../query_templates/query85.tpl