q70.sql 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. --!syntax_pg
  2. --TPC-DS Q70
  3. -- start query 1 in stream 0 using template ../query_templates/query70.tpl
  4. select
  5. sum(ss_net_profit) as total_sum
  6. ,s_state
  7. ,s_county
  8. ,grouping(s_state)+grouping(s_county) as lochierarchy
  9. ,rank() over (
  10. partition by grouping(s_state)+grouping(s_county),
  11. case when grouping(s_county) = 0 then s_state end
  12. order by sum(ss_net_profit) desc) as rank_within_parent
  13. from
  14. plato.store_sales
  15. ,plato.date_dim d1
  16. ,plato.store
  17. where
  18. d1.d_month_seq between 1212 and 1212+11
  19. and d1.d_date_sk = ss_sold_date_sk
  20. and s_store_sk = ss_store_sk
  21. and s_state in
  22. ( select s_state
  23. from (select s_state as s_state,
  24. rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking
  25. from plato.store_sales, plato.store, plato.date_dim
  26. where d_month_seq between 1212 and 1212+11
  27. and d_date_sk = ss_sold_date_sk
  28. and s_store_sk = ss_store_sk
  29. group by s_state
  30. ) tmp1
  31. where ranking <= 5
  32. )
  33. group by rollup(s_state,s_county)
  34. order by
  35. lochierarchy desc
  36. ,case when lochierarchy = 0 then s_state end
  37. ,rank_within_parent
  38. limit 100;
  39. -- end query 1 in stream 0 using template ../query_templates/query70.tpl