q67.sql 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. --!syntax_pg
  2. --TPC-DS Q67
  3. -- start query 1 in stream 0 using template ../query_templates/query67.tpl
  4. select *
  5. from (select i_category
  6. ,i_class
  7. ,i_brand
  8. ,i_product_name
  9. ,d_year
  10. ,d_qoy
  11. ,d_moy
  12. ,s_store_id
  13. ,sumsales
  14. ,rank() over (partition by i_category order by sumsales desc) rk
  15. from (select i_category
  16. ,i_class
  17. ,i_brand
  18. ,i_product_name
  19. ,d_year
  20. ,d_qoy
  21. ,d_moy
  22. ,s_store_id
  23. ,sum(coalesce(ss_sales_price*ss_quantity::numeric,0::numeric)) sumsales
  24. from plato.store_sales
  25. ,plato.date_dim
  26. ,plato.store
  27. ,plato.item
  28. where ss_sold_date_sk=d_date_sk
  29. and ss_item_sk=i_item_sk
  30. and ss_store_sk = s_store_sk
  31. and d_month_seq between 1212 and 1212+11
  32. group by rollup(i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id))dw1) dw2
  33. where rk <= 100
  34. order by i_category
  35. ,i_class
  36. ,i_brand
  37. ,i_product_name
  38. ,d_year
  39. ,d_qoy
  40. ,d_moy
  41. ,s_store_id
  42. ,sumsales
  43. ,rk
  44. limit 100;
  45. -- end query 1 in stream 0 using template ../query_templates/query67.tpl