[LeetCode] Reformat Department Table (sum, case, when, then)
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..
2021. 4. 9.
[LeetCode] Swap Salary (update, ENUM, SET, CASE, IF)
ENUM data type link ENUM(val1, val2, val3, ...) A string object that can have only one value, chosen from a list of possible values. You can list up to 65535 values in an ENUM list. If a value is inserted that is not in the list, a blank value will be inserted. The values are sorted in the order you enter them UPDATE salary SET sex = IF(sex='m', 'f', 'm'); UPDATE salary SET sex = CASE sex WHEN '..
2021. 4. 9.