Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- | id | first | last | type
- 1 mp de bill
- 1 mark ve ship
- 2 dw her bill
- 2 dwi rra ship
- | id | bill.first | bill.last | ship.first | ship.last
- 1 mp de mark ve
- 2 dw her dwi rra
- select
- t1.first,
- t1.last,
- t2.first,
- t2.last,
- t1.type
- from
- test t1
- inner join test t2
- on t1.id = t2.id
- and t1.type = 'bill'
- and t1.type != t2.type
- select bill.id, bill.first, bill.last, ship.first, ship.last
- from t as bill, t as ship
- where bill.id = ship.id
- and bill.type = 'bill'
- and ship.type = 'ship'
- SELECT b.id, b.first, b.last, s.first, s.last
- FROM bill b
- LEFT JOIN ship s ON b.id=s.id AND b.type='bill' AND s.type='ship'
- SELECT A.id,A.first, A.last,
- B.first, B.last
- FROM T2 A
- INNER JOIN T2 B
- ON A.id = B.id
- AND A.type = 'bill'
- AND B.type = 'ship'
- select id,
- max(case when type = 'bill' then first end) as "bill.first",
- max(case when type = 'bill' then last end) as "bill.last",
- max(case when type = 'ship' then first end) as "ship.first",
- max(case when type = 'ship' then last end) as "ship.last"
- from table t
- group by id;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement