-
Notifications
You must be signed in to change notification settings - Fork 118
/
1179. Reformat Department Table.sql
21 lines (21 loc) · 1.3 KB
/
1179. Reformat Department Table.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# Write your MySQL query statement below
# case-when-then-else-end: https://www.w3schools.com/sql/sql_case.asp
# https://leetcode.com/problems/reformat-department-table/discuss/376357/MySQLPostgreSQL-solutions
# Runtime: 698 ms, faster than 32.00% of MySQL online submissions for Reformat Department Table.
# Memory Usage: 0B, less than 100.00% of MySQL online submissions for Reformat Department Table.
select id,
sum(case when month = 'jan' then revenue else null end) as Jan_Revenue,
sum(case when month = 'feb' then revenue else null end) as Feb_Revenue,
sum(case when month = 'mar' then revenue else null end) as Mar_Revenue,
sum(case when month = 'apr' then revenue else null end) as Apr_Revenue,
sum(case when month = 'may' then revenue else null end) as May_Revenue,
sum(case when month = 'jun' then revenue else null end) as Jun_Revenue,
sum(case when month = 'jul' then revenue else null end) as Jul_Revenue,
sum(case when month = 'aug' then revenue else null end) as Aug_Revenue,
sum(case when month = 'sep' then revenue else null end) as Sep_Revenue,
sum(case when month = 'oct' then revenue else null end) as Oct_Revenue,
sum(case when month = 'nov' then revenue else null end) as Nov_Revenue,
sum(case when month = 'dec' then revenue else null end) as Dec_Revenue
from department
group by id
order by id