query71.sql 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738
  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. union all
  12. select cs_ext_sales_price as ext_price,
  13. cs_sold_date_sk as sold_date_sk,
  14. cs_item_sk as sold_item_sk,
  15. cs_sold_time_sk as time_sk
  16. from catalog_sales,date_dim
  17. where date_dim.d_date_sk = catalog_sales.cs_sold_date_sk
  18. and d_moy=12
  19. and d_year=2001
  20. union all
  21. select ss_ext_sales_price as ext_price,
  22. ss_sold_date_sk as sold_date_sk,
  23. ss_item_sk as sold_item_sk,
  24. ss_sold_time_sk as time_sk
  25. from store_sales,date_dim
  26. where date_dim.d_date_sk = store_sales.ss_sold_date_sk
  27. and d_moy=12
  28. and d_year=2001
  29. ) tmp ON tmp.sold_item_sk = item.i_item_sk
  30. JOIN time_dim ON tmp.time_sk = time_dim.t_time_sk
  31. where
  32. i_manager_id=1
  33. and (t_meal_time = 'breakfast' or t_meal_time = 'dinner')
  34. group by i_brand, i_brand_id,t_hour,t_minute
  35. order by ext_price desc, i_brand_id
  36. ;