简单的列转行
id num
01 17
01 22
id仅限2个
想得到如下结果:
01 17 22
或者
01 22 17
[解决办法]
select id,max(case num when 17 then 17 else 0 end),max(case num when 22 then 22 else 0 end) from table1 group by id
发布时间: 2012-01-22 22:38:43 作者: rapoo
简单的列转行
id num
01 17
01 22
id仅限2个
想得到如下结果:
01 17 22
或者
01 22 17
[解决办法]
select id,max(case num when 17 then 17 else 0 end),max(case num when 22 then 22 else 0 end) from table1 group by id