q7.sql 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. -- TPC-H/TPC-R Volume Shipping Query (Q7)
  2. -- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
  3. -- using 1680793381 as a seed to the RNG
  4. $n = select n_name, n_nationkey from plato.nation as n
  5. where n_name = 'PERU' or n_name = 'MOZAMBIQUE';
  6. $l = select
  7. l_orderkey, l_suppkey,
  8. DateTime::GetYear(cast(l_shipdate as timestamp)) as l_year,
  9. l_extendedprice * (1 - l_discount) as volume
  10. from
  11. plato.lineitem as l
  12. where
  13. cast(cast(l.l_shipdate as Timestamp) as Date)
  14. between Date('1995-01-01') and Date('1996-12-31');
  15. $j1 = select
  16. n_name as supp_nation,
  17. s_suppkey
  18. from
  19. plato.supplier as supplier
  20. join
  21. $n as n1
  22. on
  23. supplier.s_nationkey = n1.n_nationkey;
  24. $j2 = select
  25. n_name as cust_nation,
  26. c_custkey
  27. from
  28. plato.customer as customer
  29. join
  30. $n as n2
  31. on
  32. customer.c_nationkey = n2.n_nationkey;
  33. $j3 = select
  34. cust_nation, o_orderkey
  35. from
  36. plato.orders as orders
  37. join
  38. $j2 as customer
  39. on
  40. orders.o_custkey = customer.c_custkey;
  41. $j4 = select
  42. cust_nation,
  43. l_orderkey, l_suppkey,
  44. l_year,
  45. volume
  46. from
  47. $l as lineitem
  48. join
  49. $j3 as orders
  50. on
  51. lineitem.l_orderkey = orders.o_orderkey;
  52. $j5 = select
  53. supp_nation, cust_nation,
  54. l_year, volume
  55. from
  56. $j4 as lineitem
  57. join
  58. $j1 as supplier
  59. on
  60. lineitem.l_suppkey = supplier.s_suppkey
  61. where (supp_nation = 'PERU' and cust_nation = 'MOZAMBIQUE')
  62. OR (supp_nation = 'MOZAMBIQUE' and cust_nation = 'PERU');
  63. select
  64. supp_nation,
  65. cust_nation,
  66. l_year,
  67. sum(volume) as revenue
  68. from
  69. $j5 as shipping
  70. group by
  71. supp_nation,
  72. cust_nation,
  73. l_year
  74. order by
  75. supp_nation,
  76. cust_nation,
  77. l_year;