q21.sql 1.3 KB

123456789101112131415161718192021222324252627282930313233
  1. --!syntax_pg
  2. --TPC-DS Q21
  3. -- start query 1 in stream 0 using template ../query_templates/query21.tpl
  4. select *
  5. from(select w_warehouse_name
  6. ,i_item_id
  7. ,sum(case when (cast(d_date as date) < cast ('1998-04-08' as date))
  8. then inv_quantity_on_hand
  9. else 0 end) as inv_before
  10. ,sum(case when (cast(d_date as date) >= cast ('1998-04-08' as date))
  11. then inv_quantity_on_hand
  12. else 0 end) as inv_after
  13. from plato.inventory
  14. ,plato.warehouse
  15. ,plato.item
  16. ,plato.date_dim
  17. where i_current_price between 0.99::numeric and 1.49::numeric
  18. and i_item_sk = inv_item_sk
  19. and inv_warehouse_sk = w_warehouse_sk
  20. and inv_date_sk = d_date_sk
  21. and d_date between (cast ('1998-04-08' as date) - interval '30' day)::date
  22. and (cast ('1998-04-08' as date) + interval '30' day)::date
  23. group by w_warehouse_name, i_item_id) x
  24. where (case when inv_before > 0
  25. then inv_after / inv_before
  26. else null::int8
  27. end) between (2.0/3.0)::int8 and (3.0/2.0)::int8
  28. order by w_warehouse_name
  29. ,i_item_id
  30. limit 100;
  31. -- end query 1 in stream 0 using template ../query_templates/query21.tpl