原表如图:
效果:
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
原表如图:
效果:
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