q56.sql 2.1 KB

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