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

原文地址:https://www.cnblogs.com/Kingly/p/1780895.html