[LeetCode] 1179重新格式化部门表

1 题目描述

[LeetCode] 1179重新格式化部门表_第1张图片
[LeetCode] 1179重新格式化部门表_第2张图片

2 问题思路

3 解决代码

# Write your MySQL query statement below
select id,
       sum(case when month='Jan' then revenue end) Jan_Revenue,
       sum(case when month='Feb' then revenue end) Feb_Revenue,
       sum(case when month='Mar' then revenue end) Mar_Revenue,
       sum(case when month='Apr' then revenue end) Apr_Revenue,
       sum(case when month='May' then revenue end) May_Revenue,
       sum(case when month='Jun' then revenue end) Jun_Revenue,
       sum(case when month='Jul' then revenue end) Jul_Revenue,
       sum(case when month='Aug' then revenue end) Aug_Revenue,
       sum(case when month='Sep' then revenue end) Sep_Revenue,
       sum(case when month='Oct' then revenue end) Oct_Revenue,
       sum(case when month='Nov' then revenue end) Nov_Revenue,
       sum(case when month='Dec' then revenue end) Dec_Revenue
from Department t1
group by id
order by id

你可能感兴趣的:(力扣LeetCode)