Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- columnA columnB
- 1 a
- 1 b
- 1 c
- 2 a
- 2 x
- 3 z
- 3 w
- columnA columnB
- 1 a
- b
- c
- 2 a
- x
- 3 z
- w
- SELECT t1.columnnA, t2.columnB
- FROM table1 t1
- INNER JOIN table2 t2 ON t1.id = t2.id
- GROUP BY t1.columnnA, t2.columnB
- ORDER BY t1.columnnA, t2.columnB;
- SELECT (CASE WHEN rnum = 1 THEN v1.A ELSE NULL END) A, B
- FROM ( SELECT t1.columnA A,
- t2.columnB B,
- ROW_NUMBER () OVER (PARTITION BY t1.id ORDER BY t1.columnA)
- rnum
- FROM t1 INNER JOIN t2 ON (t1.id = t2.id)
- ORDER BY t1.columnA, t2.columnB) v1
- SELECT
- CASE WHEN @check != columnA THEN columnA END refcolumnA,
- columnB,
- @check:=columnA
- FROM Table1
- ,(SELECT @check:=0) t
- ORDER BY columnA
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement