首页 > 数据库技术 > 详细

sql-case列转行

时间:2015-04-17 15:30:38      阅读:129      评论:0      收藏:0      [点我收藏+]
1:对列进行逻辑判断
select ID,Score,
case
 when Score>=90 then ‘A‘
 when Score>=80 then ‘B‘
 when Score>=70 then ‘C‘
 when Score>=60 then ‘D‘
 when Score>=50 then ‘E‘
  end
from dbo.Scores

  

 
2:列转行
如果列名车位,某某,那么分数列
select stuNo,
sum(case when Subject=‘生物‘ then Score end) as 生物,
sum(case when Subject=‘数学‘ then Score end) as 数学,
sum(case when Subject=‘英语‘ then Score end) as 英语,
sum(case when Subject=‘语文‘ then Score end) as 语文
  from dbo.Scores group by StuNo

  

 

sql-case列转行

原文:http://www.cnblogs.com/mongo/p/4434839.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!