我有两个表
员工工资
salary_id emp_id salary
1 1 51000
2 2 30000
3 3 40000
4 4 20000
5 5 64000
6 6 47000
7 7 98000
员工表结构
emp_id | first_name | last_name | gender | email | mobile | dept_id | is_active
给定的薪水是
salary < 50000 as L
70000 < salary > 50000 as M
salary > 70000 as H
According to salary slab list out the employee who fall in which salary slab
最佳答案
SELECT *,
CASE
WHEN salary < 50000 THEN 'L'
WHEN salary BETWEEN 50000 AND 70000 THEN 'M'
ELSE 'H'
END CASE AS slab
FROM employee_salary
加入员工表以获取姓名/个人信息作为练习留给读者。
关于MYSQL:根据一个表的范围连接两个表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25045747/