query36.sql 916 B

123456789101112131415161718192021222324252627282930
  1. -- start query 1 in stream 0 using template query36.tpl and seed 1544728811
  2. select
  3. sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin
  4. ,i_category
  5. ,i_class
  6. ,grouping(i_category)+grouping(i_class) as lochierarchy
  7. ,rank() over (
  8. partition by grouping(i_category)+grouping(i_class),
  9. case when grouping(i_class) = 0 then i_category end
  10. order by sum(ss_net_profit)/sum(ss_ext_sales_price) asc) as rank_within_parent
  11. from
  12. store_sales
  13. ,date_dim d1
  14. ,item
  15. ,store
  16. where
  17. d1.d_year = 1999
  18. and d1.d_date_sk = ss_sold_date_sk
  19. and i_item_sk = ss_item_sk
  20. and s_store_sk = ss_store_sk
  21. and s_state in ('IN','AL','MI','MN',
  22. 'TN','LA','FL','NM')
  23. group by rollup(i_category,i_class)
  24. order by
  25. lochierarchy desc
  26. ,case when lochierarchy = 0 then i_category end
  27. ,rank_within_parent
  28. limit 100;
  29. -- end query 1 in stream 0 using template query36.tpl