q33.sql 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. --!syntax_pg
  2. --TPC-DS Q33
  3. -- start query 1 in stream 0 using template ../query_templates/query33.tpl
  4. with ss as (
  5. select
  6. i_manufact_id,sum(ss_ext_sales_price) total_sales
  7. from
  8. plato.store_sales,
  9. plato.date_dim,
  10. plato.customer_address,
  11. plato.item
  12. where
  13. i_manufact_id in (select
  14. i_manufact_id
  15. from
  16. plato.item
  17. where i_category in ('Books'))
  18. and ss_item_sk = i_item_sk
  19. and ss_sold_date_sk = d_date_sk
  20. and d_year = 1999
  21. and d_moy = 3
  22. and ss_addr_sk = ca_address_sk
  23. and ca_gmt_offset = -5::numeric
  24. group by i_manufact_id),
  25. cs as (
  26. select
  27. i_manufact_id,sum(cs_ext_sales_price) total_sales
  28. from
  29. plato.catalog_sales,
  30. plato.date_dim,
  31. plato.customer_address,
  32. plato.item
  33. where
  34. i_manufact_id in (select
  35. i_manufact_id
  36. from
  37. plato.item
  38. where i_category in ('Books'))
  39. and cs_item_sk = i_item_sk
  40. and cs_sold_date_sk = d_date_sk
  41. and d_year = 1999
  42. and d_moy = 3
  43. and cs_bill_addr_sk = ca_address_sk
  44. and ca_gmt_offset = -5::numeric
  45. group by i_manufact_id),
  46. ws as (
  47. select
  48. i_manufact_id,sum(ws_ext_sales_price) total_sales
  49. from
  50. plato.web_sales,
  51. plato.date_dim,
  52. plato.customer_address,
  53. plato.item
  54. where
  55. i_manufact_id in (select
  56. i_manufact_id
  57. from
  58. plato.item
  59. where i_category in ('Books'))
  60. and ws_item_sk = i_item_sk
  61. and ws_sold_date_sk = d_date_sk
  62. and d_year = 1999
  63. and d_moy = 3
  64. and ws_bill_addr_sk = ca_address_sk
  65. and ca_gmt_offset = -5::numeric
  66. group by i_manufact_id)
  67. select i_manufact_id ,sum(total_sales) total_sales
  68. from (select * from ss
  69. union all
  70. select * from cs
  71. union all
  72. select * from ws) tmp1
  73. group by i_manufact_id
  74. order by total_sales
  75. limit 100;
  76. -- end query 1 in stream 0 using template ../query_templates/query33.tpl