728x90
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
SUM() function calculates the sum of a set of values.
Note: NULL values are ignored.
728x90
'SQL' 카테고리의 다른 글
[LeetCode] Rank Scores (rank, dense rank, row number) (0) | 2021.04.10 |
---|---|
[LeetCode] Nth Highest Salary (set, limit) (0) | 2021.04.09 |
[LeetCode] Swap Salary (update, ENUM, SET, CASE, IF) (0) | 2021.04.09 |
[LeetCode] Not Boring Movies (0) | 2021.04.09 |
[LeetCode] Classes More Than 5 Students (group by, having, count, distinct) (0) | 2021.04.09 |
댓글