q13.sql 713 B

123456789101112131415161718192021222324252627282930313233
  1. -- TPC-H/TPC-R Customer Distribution Query (Q13)
  2. -- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
  3. -- using 1680793381 as a seed to the RNG
  4. $orders = (
  5. select
  6. o_orderkey,
  7. o_custkey
  8. from
  9. plato.orders
  10. where
  11. o_comment NOT LIKE "%unusual%requests%"
  12. );
  13. select
  14. c_count as c_count,
  15. count(*) as custdist
  16. from
  17. (
  18. select
  19. c.c_custkey as c_custkey,
  20. count(o.o_orderkey) as c_count
  21. from
  22. plato.customer as c left outer join $orders as o on
  23. c.c_custkey = o.o_custkey
  24. group by
  25. c.c_custkey
  26. ) as c_orders
  27. group by
  28. c_count
  29. order by
  30. custdist desc,
  31. c_count desc;