如图,比较“数学”,“英语”、“语文”这些科目为动态生成,列数不定,我要怎么报表上拉格式DECLARE @sql VARCHAR(8000)
SET @sql = 'SELECT ,'
SELECT @sql = @sql + 'SUM(CASE WHEN '''++''' THEN ELSE 0 END) AS '''+QUOTENAME()+''','
FROM (SELECT DISTINCT FROM ) AS a
SELECT @sql = LEFT(@sql,LEN(@sql)-1) + ' FROM GROUP BY '
PRINT(@sql)
EXEC(@sql)