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 -- id 별로 결과가 나와야하기 때문에 GROUP BY를 해줘야됨
, SUM(CASE WHEN month = "Jan" THEN revenue END) AS Jan_Revenue
-- SUM()이라는 집계함수는 null을 무시하므로 8000이 남게됨
, 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
-- MAX도 이용가능하다
FROM department
GROUP BY id -- id 별로 결과가 나와야하기 때문에 GROUP BY를 해줘야됨