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