Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. | id | first | last | type
  2. 1 mp de bill
  3. 1 mark ve ship
  4. 2 dw her bill
  5. 2 dwi rra ship
  6.  
  7. | id | bill.first | bill.last | ship.first | ship.last
  8. 1 mp de mark ve
  9. 2 dw her dwi rra
  10.  
  11. select
  12. t1.first,
  13. t1.last,
  14. t2.first,
  15. t2.last,
  16. t1.type
  17. from
  18. test t1
  19. inner join test t2
  20. on t1.id = t2.id
  21. and t1.type = 'bill'
  22. and t1.type != t2.type
  23.  
  24. select bill.id, bill.first, bill.last, ship.first, ship.last
  25. from t as bill, t as ship
  26. where bill.id = ship.id
  27. and bill.type = 'bill'
  28. and ship.type = 'ship'
  29.  
  30. SELECT b.id, b.first, b.last, s.first, s.last
  31. FROM bill b
  32. LEFT JOIN ship s ON b.id=s.id AND b.type='bill' AND s.type='ship'
  33.  
  34. SELECT A.id,A.first, A.last,
  35. B.first, B.last
  36. FROM T2 A
  37. INNER JOIN T2 B
  38. ON A.id = B.id
  39. AND A.type = 'bill'
  40. AND B.type = 'ship'
  41.  
  42. select id,
  43. max(case when type = 'bill' then first end) as "bill.first",
  44. max(case when type = 'bill' then last end) as "bill.last",
  45. max(case when type = 'ship' then first end) as "ship.first",
  46. max(case when type = 'ship' then last end) as "ship.last"
  47. from table t
  48. group by id;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement