Skip to content

Commit 9f3c87a

Browse files
authored
Create reformat-department-table.sql
1 parent 2e6cfd3 commit 9f3c87a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

MySQL/reformat-department-table.sql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Time: O(n)
2+
# Space: O(n)
3+
4+
SELECT id,
5+
SUM(IF(month = 'Jan', revenue, NULL)) AS Jan_Revenue,
6+
SUM(IF(month = 'Feb', revenue, NULL)) AS Feb_Revenue,
7+
SUM(IF(month = 'Mar', revenue, NULL)) AS Mar_Revenue,
8+
SUM(IF(month = 'Apr', revenue, NULL)) AS Apr_Revenue,
9+
SUM(IF(month = 'May', revenue, NULL)) AS May_Revenue,
10+
SUM(IF(month = 'Jun', revenue, NULL)) AS Jun_Revenue,
11+
SUM(IF(month = 'Jul', revenue, NULL)) AS Jul_Revenue,
12+
SUM(IF(month = 'Aug', revenue, NULL)) AS Aug_Revenue,
13+
SUM(IF(month = 'Sep', revenue, NULL)) AS Sep_Revenue,
14+
SUM(IF(month = 'Oct', revenue, NULL)) AS Oct_Revenue,
15+
SUM(IF(month = 'Nov', revenue, NULL)) AS Nov_Revenue,
16+
SUM(IF(month = 'Dec', revenue, NULL)) AS Dec_Revenue
17+
FROM department
18+
GROUP BY id;

0 commit comments

Comments
 (0)