Advertisement
Guest User

Untitled

a guest
Feb 6th, 2016
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. drop table if exists hawqsql.q2_minimum_cost_supplier_tmp1;
  2. create table hawqsql.q2_minimum_cost_supplier_tmp1 (s_acctbal double precision, s_name text, n_name text, p_partkey int, ps_supplycost double precision, p_mfgr text, s_address text, s_phone text, s_comment text);
  3. drop table if exists hawqsql.q2_minimum_cost_supplier_tmp2;
  4. create table hawqsql.q2_minimum_cost_supplier_tmp2 (p_partkey int, ps_min_supplycost double precision);
  5. drop table if exists hawqsql.q2_minimum_cost_supplier;
  6. create table hawqsql.q2_minimum_cost_supplier (s_acctbal double precision, s_name text, n_name text, p_partkey int, p_mfgr text, s_address text, s_phone text, s_comment text);
  7.  
  8. -- the query
  9. insert into hawqsql.q2_minimum_cost_supplier_tmp1
  10. select
  11. s.s_acctbal,
  12. s.s_name,
  13. n.n_name,
  14. p.p_partkey,
  15. ps.ps_supplycost,
  16. p.p_mfgr,
  17. s.s_address,
  18. s.s_phone,
  19. s.s_comment
  20. from
  21. hawqsql.nation n join hawqsql.region r
  22. on
  23. n.n_regionkey = r.r_regionkey and r.r_name = 'EUROPE'
  24. join hawqsql.supplier s
  25. on
  26. s.s_nationkey = n.n_nationkey
  27. join hawqsql.partsupp ps
  28. on
  29. s.s_suppkey = ps.ps_suppkey
  30. join hawqsql.part p
  31. on
  32. p.p_partkey = ps.ps_partkey
  33. and
  34. p.p_size = 37 and p.p_type like '%COPPER' ;
  35.  
  36. insert overwrite table q2_minimum_cost_supplier_tmp2
  37. select
  38. p_partkey, min(ps_supplycost)
  39. from
  40. q2_minimum_cost_supplier_tmp1
  41. group by p_partkey;
  42.  
  43. insert overwrite table q2_minimum_cost_supplier
  44. select
  45. t1.s_acctbal,
  46. t1.s_name,
  47. t1.n_name,
  48. t1.p_partkey,
  49. t1.p_mfgr,
  50. t1.s_address,
  51. t1.s_phone,
  52. t1.s_comment
  53. from
  54. hawqsql.q2_minimum_cost_supplier_tmp1 t1 join hawqsql.q2_minimum_cost_supplier_tmp2 t2
  55. on
  56. t1.p_partkey = t2.p_partkey
  57. and
  58. t1.ps_supplycost=t2.ps_min_supplycost
  59. order by
  60. s_acctbal desc, n_name, s_name, p_partkey
  61. limit 100;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement