sqlserver 行列旋转
有表![]()
![](http://images0.cnblogs.com/blog/136909/201309/11084512-77856ad420d748f6b56d678c0736678b.jpg)
要求查询结果
![](http://images0.cnblogs.com/blog/136909/201309/11084523-44466e7e0d7b421e9d7bda00deed2737.jpg)
sqlserver 语句:
select Name as 姓名,
max(case KeMu when '语文' then FenShu else 0 end) 语文,
max(case KeMu when '数学' then FenShu else 0 end) 数学,
max(case KeMu when '英语' then FenShu else 0 end) 英语
from Tab_score
group by Name
结果: