forked from Kyrylo-Ktl/LeetCode-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReformat Department Table.sql
More file actions
16 lines (16 loc) · 958 Bytes
/
Reformat Department Table.sql
File metadata and controls
16 lines (16 loc) · 958 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
SELECT
id,
MAX(CASE WHEN month = 'Jan' THEN revenue ELSE null END) AS Jan_Revenue,
MAX(CASE WHEN month = 'Feb' THEN revenue ELSE null END) AS Feb_Revenue,
MAX(CASE WHEN month = 'Mar' THEN revenue ELSE null END) AS Mar_Revenue,
MAX(CASE WHEN month = 'Apr' THEN revenue ELSE null END) AS Apr_Revenue,
MAX(CASE WHEN month = 'May' THEN revenue ELSE null END) AS May_Revenue,
MAX(CASE WHEN month = 'Jun' THEN revenue ELSE null END) AS Jun_Revenue,
MAX(CASE WHEN month = 'Jul' THEN revenue ELSE null END) AS Jul_Revenue,
MAX(CASE WHEN month = 'Aug' THEN revenue ELSE null END) AS Aug_Revenue,
MAX(CASE WHEN month = 'Sep' THEN revenue ELSE null END) AS Sep_Revenue,
MAX(CASE WHEN month = 'Oct' THEN revenue ELSE null END) AS Oct_Revenue,
MAX(CASE WHEN month = 'Nov' THEN revenue ELSE null END) AS Nov_Revenue,
MAX(CASE WHEN month = 'Dec' THEN revenue ELSE null END) AS Dec_Revenue
FROM Department
GROUP BY id;