q20.sql 564 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. --!syntax_pg
  2. --TPC-H Q20
  3. select
  4. s_name,
  5. s_address
  6. from
  7. plato."supplier",
  8. plato."nation"
  9. where
  10. s_suppkey in (
  11. select
  12. ps_suppkey
  13. from
  14. plato."partsupp"
  15. where
  16. ps_partkey in (
  17. select
  18. p_partkey
  19. from
  20. plato."part"
  21. where
  22. p_name like 'forest%'
  23. )
  24. and ps_availqty::numeric > (
  25. select
  26. 0.5::numeric * sum(l_quantity)
  27. from
  28. plato."lineitem"
  29. where
  30. l_partkey = ps_partkey
  31. and l_suppkey = ps_suppkey
  32. and l_shipdate >= '1994-01-01'::date
  33. and l_shipdate < '1994-01-01'::date + interval '1' year
  34. )
  35. )
  36. and s_nationkey = n_nationkey
  37. and n_name = 'CANADA'
  38. order by
  39. s_name;