Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- github
- sql
- RLIKE
- programmers
- leetcode
- L1정규화
- window function
- Git
- 버전충돌
- PYTHON
- L2정규화
- HTML
- 깃헙협업
- hackerrank
- 클라우드컴퓨팅
- 편향-분산 교환
- coding
- AWS
- full request
- merge
- conflict
- mysql
- early stopping
- 온라인협업
- 교차 엔트로피
- 코딩공부
- branch
- elastic net
- 선형 모형
- CSS
Archives
- Today
- Total
Im between cherry
Leet Code | MySQL | 1179. Reformat Department Table 본문
1179. Reformat Department Table
https://leetcode.com/problems/reformat-department-table/
Write an SQL query to reformat the table such that there is a department id column and a revenue column for each month.
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
/*
{"headers": ["id", "revenue", "month"],
"values": [[1, 8000, "Jan"], [2, 9000, "Jan"],
[3, 10000, "Feb"], [1, 7000, "Feb"], [1, 6000, "Mar"]]}
*/
'데이터분석 > practice_query' 카테고리의 다른 글
Programmers | MySQL | [SELECT] 역순 정렬하기 (0) | 2020.08.30 |
---|---|
Programmers | MySQL | 모든 레코드 조회하기 (0) | 2020.08.30 |
Leet Code | MySQL | 183. Customers Who Never Order (0) | 2020.08.30 |
Leet Code | MySQL | 197. Rising Temperature (0) | 2020.08.30 |
Leet Code | MySQL | 185. Department Top Three Salaries (0) | 2020.08.30 |
Comments