日期:2014-05-17 浏览次数:20642 次
declare @s nvarchar(4000)set @s=''Select @s=@s+','+quotename([Course])+'=max(case when [Course]='+quotename([Course],'''')+' then [Score] else 0 end)'from Class group by[Course]exec('select [Student]'+@s+' from Class group by [Student]')
DECLARE @s NVARCHAR(4000)
SET @s = ''
SELECT @s = @s + ',' + QUOTENAME([Course]) + '=max(case when [Course]='
+ QUOTENAME([Course], '''') + ' then [Score] else 0 end)'
FROM (SELECT * FROM Class ORDER BY [日期]) Class
GROUP BY [Course]
EXEC('select [Student]'+@s+' from Class group by [Student]')
declare @s nvarchar(4000)
set @s=''
Select @s=@s+','+quotename(CONVERT(varchar(10),日期列,120))+'=max(case when CONVERT(varchar(10),日期列,120)='+quotename([日期列],'''')+' then [Score] else 0 end)'
from Class
group by CONVERT(varchar(10),日期列,120)
order by Min(日期列)