假设
问题 次数 得分 分别是 wt cs df 表a
declare @sql varchar(8000)
set @sql='select wt as 问题 '
select @sql=@sql+char(13)
+',sum(case cs when '''+cs+''' then cast(df as int) end) as '+cs
from (select distinct cs from a) aa
set @sql=@sql+char(13)+'from a group by wt'
exec(@sql)