q07.sql 800 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. --!syntax_pg
  2. --TPC-H Q7
  3. select
  4. supp_nation,
  5. cust_nation,
  6. l_year, sum(volume) as revenue
  7. from (
  8. select
  9. n1.n_name as supp_nation,
  10. n2.n_name as cust_nation,
  11. extract(year from l_shipdate) as l_year,
  12. l_extendedprice * (1::numeric - l_discount) as volume
  13. from
  14. plato."supplier",
  15. plato."lineitem",
  16. plato."orders",
  17. plato."customer",
  18. plato."nation" n1,
  19. plato."nation" n2
  20. where
  21. s_suppkey = l_suppkey
  22. and o_orderkey = l_orderkey
  23. and c_custkey = o_custkey
  24. and s_nationkey = n1.n_nationkey
  25. and c_nationkey = n2.n_nationkey
  26. and (
  27. (n1.n_name = 'FRANCE' and n2.n_name = 'GERMANY')
  28. or (n1.n_name = 'GERMANY' and n2.n_name = 'FRANCE')
  29. )
  30. and l_shipdate between date '1995-01-01' and date '1996-12-31'
  31. ) as shipping
  32. group by
  33. supp_nation,
  34. cust_nation,
  35. l_year
  36. order by
  37. supp_nation,
  38. cust_nation,
  39. l_year;