1
0

tpch_query21.sql 943 B

123456789101112131415161718192021222324252627282930313233343536
  1. -- explain
  2. create temporary table l3 stored as orc as
  3. select l_orderkey, count(distinct l_suppkey) as cntSupp
  4. from lineitem
  5. where l_receiptdate > l_commitdate and l_orderkey is not null
  6. group by l_orderkey
  7. having cntSupp = 1
  8. ;
  9. with location as (
  10. select supplier.* from supplier, nation where
  11. s_nationkey = n_nationkey and n_name = 'SAUDI ARABIA'
  12. )
  13. select s_name, count(*) as numwait
  14. from
  15. (
  16. select li.l_suppkey, li.l_orderkey
  17. from lineitem li join orders o on li.l_orderkey = o.o_orderkey and
  18. o.o_orderstatus = 'F'
  19. join
  20. (
  21. select l_orderkey, count(distinct l_suppkey) as cntSupp
  22. from lineitem
  23. group by l_orderkey
  24. ) l2 on li.l_orderkey = l2.l_orderkey and
  25. li.l_receiptdate > li.l_commitdate and
  26. l2.cntSupp > 1
  27. ) l1 join l3 on l1.l_orderkey = l3.l_orderkey
  28. join location s on l1.l_suppkey = s.s_suppkey
  29. group by
  30. s_name
  31. order by
  32. numwait desc,
  33. s_name
  34. limit 100;