sqlServer2005 行转列(case when用法)
数据库原来的数据:如下图
修改后的数据:
select ball as "球",sum(case type when '红' then num else 0 end) as '红',
sum(case type when '蓝' then num else 0 end) as '蓝',
sum(case type when '绿' then num else 0 end) as '绿'
from T_ball group by ball;
如下图