q15.sql 588 B

123456789101112131415161718192021222324252627282930313233343536
  1. --!syntax_pg
  2. --ignore runonopt plan diff
  3. --TPC-H Q15
  4. create view revenue_STREAM_ID (supplier_no, total_revenue) as
  5. select
  6. l_suppkey,
  7. sum(l_extendedprice * (1::numeric - l_discount))
  8. from
  9. plato."lineitem"
  10. where
  11. l_shipdate >= date '1996-01-01'
  12. and l_shipdate < date '1996-01-01' + interval '3' month
  13. group by
  14. l_suppkey;
  15. select
  16. s_suppkey,
  17. s_name,
  18. s_address,
  19. s_phone,
  20. total_revenue
  21. from
  22. plato."supplier",
  23. revenue_STREAM_ID
  24. where
  25. s_suppkey = supplier_no
  26. and total_revenue = (
  27. select
  28. max(total_revenue)
  29. from
  30. revenue_STREAM_ID
  31. )
  32. order by
  33. s_suppkey;
  34. drop view revenue_STREAM_ID;