query71.sql 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. select i_brand_id brand_id, i_brand brand,t_hour,t_minute,
  2. sum(ext_price) ext_price
  3. from item JOIN (select ws_ext_sales_price as ext_price,
  4. ws_sold_date_sk as sold_date_sk,
  5. ws_item_sk as sold_item_sk,
  6. ws_sold_time_sk as time_sk
  7. from web_sales,date_dim
  8. where date_dim.d_date_sk = web_sales.ws_sold_date_sk
  9. and d_moy=12
  10. and d_year=2001
  11. and ws_sold_date between '2001-12-01' and '2001-12-31'
  12. union all
  13. select cs_ext_sales_price as ext_price,
  14. cs_sold_date_sk as sold_date_sk,
  15. cs_item_sk as sold_item_sk,
  16. cs_sold_time_sk as time_sk
  17. from catalog_sales,date_dim
  18. where date_dim.d_date_sk = catalog_sales.cs_sold_date_sk
  19. and d_moy=12
  20. and d_year=2001
  21. and cs_sold_date between '2001-12-01' and '2001-12-31'
  22. union all
  23. select ss_ext_sales_price as ext_price,
  24. ss_sold_date_sk as sold_date_sk,
  25. ss_item_sk as sold_item_sk,
  26. ss_sold_time_sk as time_sk
  27. from store_sales,date_dim
  28. where date_dim.d_date_sk = store_sales.ss_sold_date_sk
  29. and d_moy=12
  30. and d_year=2001
  31. and ss_sold_date between '2001-12-01' and '2001-12-31'
  32. ) tmp ON tmp.sold_item_sk = item.i_item_sk
  33. JOIN time_dim ON tmp.time_sk = time_dim.t_time_sk
  34. where
  35. i_manager_id=1
  36. and (t_meal_time = 'breakfast' or t_meal_time = 'dinner')
  37. group by i_brand, i_brand_id,t_hour,t_minute
  38. order by ext_price desc, i_brand_id
  39. ;