![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/9b67e5285fd84cf4e7aa4067eceb9380.png)
SELECT id,
[Jan] AS [Jan_Revenue],
[Feb] AS [Feb_Revenue],
[Mar] AS [Mar_Revenue],
[Apr] AS [Apr_Revenue],
...
FROM Department
PIVOT
(
sum(revenue)
FOR month in ([Jan],[Feb],[Mar],[Apr],[May],[Jun],[Jul],[Aug],[Sep],[Oct],[Nov],[Dec])
)AS pivot_month
SELECT id,
sum(CASE month WHEN 'Jan' THEN revenue END) AS Jan_Revenue,
sum(CASE month WHEN 'Feb' THEN revenue END) AS Feb_Revenue,
sum(CASE month WHEN 'Mar' THEN revenue END) AS Mar_Revenue,
sum(CASE month WHEN 'Apr' THEN revenue END) AS Apr_Revenue,
sum(CASE month WHEN 'May' THEN revenue END) AS May_Revenue,
sum(CASE month WHEN 'Jun' THEN revenue END) AS Jun_Revenue,
sum(CASE month WHEN 'Jul' THEN revenue END) AS Jul_Revenue,
sum(CASE month WHEN 'Aug' THEN revenue END) AS Aug_Revenue,
sum(CASE month WHEN 'Sep' THEN revenue END) AS Sep_Revenue,
sum(CASE month WHEN 'Oct' THEN revenue END) AS Oct_Revenue,
sum(CASE month WHEN 'Nov' THEN revenue END) AS Nov_Revenue,
sum(CASE month WHEN 'Dec' THEN revenue END) AS Dec_Revenue
FROM Department
GROUP BY id