1
0

query56.sql 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. with ss as (
  2. select i_item_id,sum(ss_ext_sales_price) total_sales
  3. from
  4. store_sales,
  5. date_dim,
  6. customer_address,
  7. item
  8. where item.i_item_id in (select
  9. i.i_item_id
  10. from item i
  11. where i_color in ('purple','burlywood','indian'))
  12. and ss_item_sk = i_item_sk
  13. and ss_sold_date_sk = d_date_sk
  14. and d_year = 2001
  15. and d_moy = 1
  16. and ss_addr_sk = ca_address_sk
  17. and ca_gmt_offset = -6
  18. group by i_item_id),
  19. cs as (
  20. select i_item_id,sum(cs_ext_sales_price) total_sales
  21. from
  22. catalog_sales,
  23. date_dim,
  24. customer_address,
  25. item
  26. where
  27. item.i_item_id in (select
  28. i.i_item_id
  29. from item i
  30. where i_color in ('purple','burlywood','indian'))
  31. and cs_item_sk = i_item_sk
  32. and cs_sold_date_sk = d_date_sk
  33. and d_year = 2001
  34. and d_moy = 1
  35. and cs_bill_addr_sk = ca_address_sk
  36. and ca_gmt_offset = -6
  37. group by i_item_id),
  38. ws as (
  39. select i_item_id,sum(ws_ext_sales_price) total_sales
  40. from
  41. web_sales,
  42. date_dim,
  43. customer_address,
  44. item
  45. where
  46. item.i_item_id in (select
  47. i.i_item_id
  48. from item i
  49. where i_color in ('purple','burlywood','indian'))
  50. and ws_item_sk = i_item_sk
  51. and ws_sold_date_sk = d_date_sk
  52. and d_year = 2001
  53. and d_moy = 1
  54. and ws_bill_addr_sk = ca_address_sk
  55. and ca_gmt_offset = -6
  56. group by i_item_id)
  57. select i_item_id ,sum(total_sales) total_sales
  58. from (select * from ss
  59. union all
  60. select * from cs
  61. union all
  62. select * from ws) tmp1
  63. group by i_item_id
  64. order by total_sales
  65. limit 100;