q11.sql 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. -- TPC-H/TPC-R Important Stock Identification Query (Q11)
  2. -- TPC TPC-H Parameter Substitution (Version 2.17.2 build 0)
  3. -- using 1680793381 as a seed to the RNG
  4. PRAGMA DisableSimpleColumns;
  5. $join1 = (
  6. select
  7. ps.ps_partkey as ps_partkey,
  8. ps.ps_supplycost as ps_supplycost,
  9. ps.ps_availqty as ps_availqty,
  10. s.s_nationkey as s_nationkey
  11. from
  12. plato.partsupp as ps
  13. join
  14. plato.supplier as s
  15. on
  16. ps.ps_suppkey = s.s_suppkey
  17. );
  18. $join2 = (
  19. select
  20. j.ps_partkey as ps_partkey,
  21. j.ps_supplycost as ps_supplycost,
  22. j.ps_availqty as ps_availqty,
  23. j.s_nationkey as s_nationkey
  24. from
  25. $join1 as j
  26. join
  27. plato.nation as n
  28. on
  29. n.n_nationkey = j.s_nationkey
  30. where
  31. n.n_name = 'CANADA'
  32. );
  33. $threshold = (
  34. select
  35. sum(ps_supplycost * ps_availqty) * 0.0001000000 as threshold
  36. from
  37. $join2
  38. );
  39. $values = (
  40. select
  41. ps_partkey,
  42. sum(ps_supplycost * ps_availqty) as value
  43. from
  44. $join2
  45. group by
  46. ps_partkey
  47. );
  48. select
  49. v.ps_partkey as ps_partkey,
  50. v.value as value
  51. from
  52. $values as v
  53. cross join
  54. $threshold as t
  55. where
  56. v.value > t.threshold
  57. order by
  58. value desc;