728x90
반응형
CASE WHEN PIVOT LEETCODE 문제
- https://leetcode.com/problems/reformat-department-table/
- 요약하면 department 별 1~12월 수입을 출력.
풀이
select
id
,sum(case when month = 'Jan' then revenue end) as Jan_Revenue
,sum(case when month = 'Feb' then revenue end) as Feb_Revenue
,sum(case when month = 'Mar' then revenue end) as Mar_Revenue
,sum(case when month = 'Apr' then revenue end) as Apr_Revenue
,sum(case when month = 'May' then revenue end) as May_Revenue
,sum(case when month = 'Jun' then revenue end) as Jun_Revenue
,sum(case when month = 'Jul' then revenue end) as Jul_Revenue
,sum(case when month = 'Aug' then revenue end) as Aug_Revenue
,sum(case when month = 'Sep' then revenue end) as Sep_Revenue
,sum(case when month = 'Oct' then revenue end) as Oct_Revenue
,sum(case when month = 'Nov' then revenue end) as Nov_Revenue
,sum(case when month = 'Dec' then revenue end) as Dec_Revenue
from
Department
group by id
;
'algorithm > leetcode' 카테고리의 다른 글
[leetcode] Number of Islands 정리 (0) | 2022.01.28 |
---|---|
leetcode Employees Earning More Than Their Managers 풀이 (0) | 2020.09.30 |
[LeetCode] ReverseInteger (0) | 2020.07.11 |
[LeetCode] LongestSubstring (0) | 2020.07.11 |
[LeetCode] LongestPalindromicSubstring (0) | 2020.07.11 |
댓글