q12.sql 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. -- TPC-H/TPC-R Shipping Modes and Order Priority Query (Q12)
  2. -- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
  3. -- using 1680793381 as a seed to the RNG
  4. $join = (
  5. select
  6. l.l_shipmode as l_shipmode,
  7. o.o_orderpriority as o_orderpriority,
  8. l.l_commitdate as l_commitdate,
  9. l.l_shipdate as l_shipdate,
  10. l.l_receiptdate as l_receiptdate
  11. from
  12. plato.orders as o
  13. join plato.lineitem as l
  14. on o.o_orderkey == l.l_orderkey
  15. );
  16. $border = Date("1994-01-01");
  17. select
  18. l_shipmode,
  19. sum(case
  20. when o_orderpriority = '1-URGENT'
  21. or o_orderpriority = '2-HIGH'
  22. then 1
  23. else 0
  24. end) as high_line_count,
  25. sum(case
  26. when o_orderpriority <> '1-URGENT'
  27. and o_orderpriority <> '2-HIGH'
  28. then 1
  29. else 0
  30. end) as low_line_count
  31. from $join
  32. where
  33. (l_shipmode = 'MAIL' or l_shipmode = 'TRUCK')
  34. and l_commitdate < l_receiptdate
  35. and l_shipdate < l_commitdate
  36. and cast(l_receiptdate as timestamp) >= $border
  37. and cast(l_receiptdate as timestamp) < ($border + Interval("P365D"))
  38. group by
  39. l_shipmode
  40. order by
  41. l_shipmode;