q09.sql 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. --!syntax_pg
  2. --TPC-DS Q9
  3. -- start query 1 in stream 0 using template ../query_templates/query9.tpl
  4. select case when (select count(*)
  5. from plato.store_sales
  6. where ss_quantity between 1 and 20) > 25437
  7. then (select avg(ss_ext_discount_amt)
  8. from plato.store_sales
  9. where ss_quantity between 1 and 20)
  10. else (select avg(ss_net_profit)
  11. from plato.store_sales
  12. where ss_quantity between 1 and 20) end bucket1 ,
  13. case when (select count(*)
  14. from plato.store_sales
  15. where ss_quantity between 21 and 40) > 22746
  16. then (select avg(ss_ext_discount_amt)
  17. from plato.store_sales
  18. where ss_quantity between 21 and 40)
  19. else (select avg(ss_net_profit)
  20. from plato.store_sales
  21. where ss_quantity between 21 and 40) end bucket2,
  22. case when (select count(*)
  23. from plato.store_sales
  24. where ss_quantity between 41 and 60) > 9387
  25. then (select avg(ss_ext_discount_amt)
  26. from plato.store_sales
  27. where ss_quantity between 41 and 60)
  28. else (select avg(ss_net_profit)
  29. from plato.store_sales
  30. where ss_quantity between 41 and 60) end bucket3,
  31. case when (select count(*)
  32. from plato.store_sales
  33. where ss_quantity between 61 and 80) > 10098
  34. then (select avg(ss_ext_discount_amt)
  35. from plato.store_sales
  36. where ss_quantity between 61 and 80)
  37. else (select avg(ss_net_profit)
  38. from plato.store_sales
  39. where ss_quantity between 61 and 80) end bucket4,
  40. case when (select count(*)
  41. from plato.store_sales
  42. where ss_quantity between 81 and 100) > 18213
  43. then (select avg(ss_ext_discount_amt)
  44. from plato.store_sales
  45. where ss_quantity between 81 and 100)
  46. else (select avg(ss_net_profit)
  47. from plato.store_sales
  48. where ss_quantity between 81 and 100) end bucket5
  49. from plato.reason
  50. where r_reason_sk = 1
  51. ;
  52. -- end query 1 in stream 0 using template ../query_templates/query9.tpl