--第一种方法 declare @sql varchar(8000) set @sql = 'select name as ' + '姓名' select @sql = @sql + ',max(case Subject when ''' + Subject + ''' then Result else 0 end) [' + Subject + ']'from (select distinct Subject from table_Test) as a set @sql = @sql + ' from table_Test group by name' exec(@sql) --第二种方法 select name,sum(case subject when'数学' then Result else 0 end ) as '数学',sum(case subject when'英语' then Result else 0 end ) as '英语',sum(case subject when'语文' then Result else 0 end ) as '语文' from table_Test group by name --========================================================================
总结以上是内存溢出为你收集整理的sqlserver纵横表的转换全部内容,希望文章能够帮你解决sqlserver纵横表的转换所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)