日期:2014-05-17 浏览次数:20478 次
SELECT *
FROM (
SELECT [区域]
,'工资' AS [月份]
,SUM(CASE WHEN '月份'='1月' THEN [工资] ELSE 0 END) AS [1月]
,SUM(CASE WHEN '月份'='2月' THEN [工资] ELSE 0 END) AS [2月]
,SUM(CASE WHEN '月份'='3月' THEN [工资] ELSE 0 END) AS [3月]
FROM TB
GROUP BY [区域]
UNION ALL
SELECT [区域]
,'福利' AS [月份]
,SUM(CASE WHEN '月份'='1月' THEN [福利] ELSE 0 END) AS [1月]
,SUM(CASE WHEN '月份'='2月' THEN [福利] ELSE 0 END) AS [2月]
,SUM(CASE WHEN '月份'='3月' THEN [福利] ELSE 0 END) AS [3月]
FROM TB
GROUP BY [区域]
UNION ALL
SELECT [区域]
,'奖金' AS [月份]
,SUM(CASE WHEN '月份'='1月' THEN [奖金] ELSE 0 END) AS [1月]
,SUM(CASE WHEN '月份'='2月' THEN [奖金] ELSE 0 END) AS [2月]
,