行转列的问题
查询结果如下:
id num
01 0
01 1
01 -1
希望得到如下结果
id n1 n2 n3
01 0 1 -1
------解决方案--------------------select a.id from tb a
left join (select * from tb where num = 0) t1 on a.id = t1.id
left join (select * from tb where num = 1) t2 on a.id = t2.id
left join (select * from tb where num = -1) t3 on a.id = t3.id