tpch_query7.sql 748 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. select
  2. supp_nation,
  3. cust_nation,
  4. l_year,
  5. sum(volume) as revenue
  6. from
  7. (
  8. select
  9. n1.n_name as supp_nation,
  10. n2.n_name as cust_nation,
  11. year(l_shipdate) as l_year,
  12. l_extendedprice * (1 - l_discount) as volume
  13. from
  14. supplier,
  15. lineitem,
  16. orders,
  17. customer,
  18. nation n1,
  19. 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 = 'KENYA' and n2.n_name = 'PERU')
  28. or (n1.n_name = 'PERU' and n2.n_name = 'KENYA')
  29. )
  30. and l_shipdate between '1995-01-01' and '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;