CASE | |
WHEN condition1 THEN result1 | |
WHEN condition2 THEN result2 | |
... | |
ELSE resultN | |
END |
SELECT | |
employee_id, | |
salary, | |
CASE | |
WHEN salary < 3000 THEN 'Low' | |
WHEN salary BETWEEN 3000 AND 7000 THEN 'Medium' | |
WHEN salary > 7000 THEN 'High' | |
ELSE 'Unknown' | |
END AS salary_level | |
FROM | |
employees; |
UPDATE | |
employees | |
SET | |
salary_category = CASE | |
WHEN salary < 3000 THEN 'Low' | |
WHEN salary BETWEEN 3000 AND 7000 THEN 'Medium' | |
WHEN salary > 7000 THEN 'High' | |
ELSE 'Unknown' | |
END; |
SELECT | |
CASE | |
WHEN salary < 3000 THEN 'Low' | |
WHEN salary BETWEEN 3000 AND 7000 THEN 'Medium' | |
WHEN salary > 7000 THEN 'High' | |
ELSE 'Unknown' | |
END AS salary_level, | |
COUNT(*) AS num_employees | |
FROM | |
employees | |
GROUP BY | |
CASE | |
WHEN salary < 3000 THEN 'Low' | |
WHEN salary BETWEEN 3000 AND 7000 THEN 'Medium' | |
WHEN salary > 7000 THEN 'High' | |
ELSE 'Unknown' | |
END; |
欢迎光临 ToB企服应用市场:ToB评测及商务社交产业平台 (https://dis.qidao123.com/) | Powered by Discuz! X3.4 |