q63.sql 1.5 KB

1234567891011121314151617181920212223242526272829303132
  1. --!syntax_pg
  2. --TPC-DS Q63
  3. -- start query 1 in stream 0 using template ../query_templates/query63.tpl
  4. select *
  5. from (select i_manager_id
  6. ,sum(ss_sales_price) sum_sales
  7. ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales
  8. from plato.item
  9. ,plato.store_sales
  10. ,plato.date_dim
  11. ,plato.store
  12. where ss_item_sk = i_item_sk
  13. and ss_sold_date_sk = d_date_sk
  14. and ss_store_sk = s_store_sk
  15. and d_month_seq in (1212,1212+1,1212+2,1212+3,1212+4,1212+5,1212+6,1212+7,1212+8,1212+9,1212+10,1212+11)
  16. and (( i_category in ('Books','Children','Electronics')
  17. and i_class in ('personal','portable','reference','self-help')
  18. and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7',
  19. 'exportiunivamalg #9','scholaramalgamalg #9'))
  20. or( i_category in ('Women','Music','Men')
  21. and i_class in ('accessories','classical','fragrances','pants')
  22. and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1',
  23. 'importoamalg #1')))
  24. group by i_manager_id, d_moy) tmp1
  25. where case when avg_monthly_sales > 0::numeric then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null::numeric end > 0.1::numeric
  26. order by i_manager_id
  27. ,avg_monthly_sales
  28. ,sum_sales
  29. limit 100;
  30. -- end query 1 in stream 0 using template ../query_templates/query63.tpl