学海无涯

导航

Sql技巧

行转列,表1:源数据,表2:转换后的数据

 

 

select Name,
sum(case Subject when '语文'  then Score else 0 end) as '语文',
sum(case Subject when '数学'  then Score else 0 end) as '数学',
sum(case Subject when '英语'  then Score else 0 end) as '英语'
from Test group by Name

 查询时显示行号

select *,ROW_NUMBER() over(order by id) as RowNum  from myTest

  

 

posted on 2022-09-19 18:59  宁静致远.  阅读(20)  评论(0编辑  收藏  举报