SQL透视表

 

原表如图:

效果:

 

SQL:

select id, sum(case when type=1 then rate else 0 end) as f1,
sum(case when type=2 then rate else 0 end) as f2,
sum(case when type=3 then rate else 0 end) as f3
from table1
group by id

posted on 2010-07-19 20:27  Kingly  阅读(253)  评论(0编辑  收藏  举报