sql-case列转行

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

  

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。