日期:2014-05-17 浏览次数:20407 次
DECLARE @s NVARCHAR(4000)
SET @s = ''
SELECT @s = @s + ',' + QUOTENAME([week]) + '=max(case when [week]='
+ QUOTENAME([week], '''') + ' then [amount] else 0 end)'
FROM tb
GROUP BY [year],[quarter]
EXEC('select [year],[quarter]'+@s+' from tb group by [year],[quarter]')