q17.sql 737 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. -- TPC-H/TPC-R Small-Quantity-Order Revenue Query (Q17)
  2. -- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
  3. -- using 1680793381 as a seed to the RNG
  4. $threshold = (
  5. select
  6. 0.2 * avg(l_quantity) as threshold,
  7. l_partkey
  8. from
  9. plato.lineitem
  10. group by
  11. l_partkey
  12. );
  13. $join1 = (
  14. select
  15. p.p_partkey as p_partkey,
  16. l.l_extendedprice as l_extendedprice,
  17. l.l_quantity as l_quantity
  18. from
  19. plato.lineitem as l
  20. join
  21. plato.part as p
  22. on
  23. p.p_partkey = l.l_partkey
  24. where
  25. p.p_brand = 'Brand#35'
  26. and p.p_container = 'LG DRUM'
  27. );
  28. select
  29. sum(j.l_extendedprice) / 7.0 as avg_yearly
  30. from
  31. $join1 as j
  32. join
  33. $threshold as t
  34. on
  35. j.p_partkey = t.l_partkey
  36. where
  37. j.l_quantity < t.threshold;