tpch_query2.sql 849 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. drop view q2_min_ps_supplycost;
  2. create view q2_min_ps_supplycost as
  3. select
  4. p_partkey as min_p_partkey,
  5. min(ps_supplycost) as min_ps_supplycost
  6. from
  7. part,
  8. partsupp,
  9. supplier,
  10. nation,
  11. region
  12. where
  13. p_partkey = ps_partkey
  14. and s_suppkey = ps_suppkey
  15. and s_nationkey = n_nationkey
  16. and n_regionkey = r_regionkey
  17. and r_name = 'EUROPE'
  18. group by
  19. p_partkey;
  20. select
  21. s_acctbal,
  22. s_name,
  23. n_name,
  24. p_partkey,
  25. p_mfgr,
  26. s_address,
  27. s_phone,
  28. s_comment
  29. from
  30. part,
  31. supplier,
  32. partsupp,
  33. nation,
  34. region,
  35. q2_min_ps_supplycost
  36. where
  37. p_partkey = ps_partkey
  38. and s_suppkey = ps_suppkey
  39. and p_size = 37
  40. and p_type like '%COPPER'
  41. and s_nationkey = n_nationkey
  42. and n_regionkey = r_regionkey
  43. and r_name = 'EUROPE'
  44. and ps_supplycost = min_ps_supplycost
  45. and p_partkey = min_p_partkey
  46. order by
  47. s_acctbal desc,
  48. n_name,
  49. s_name,
  50. p_partkey
  51. limit 100;