MySQL学习笔记汇总(三)
四、进阶1、2测试题
1、查询工资大于12000 的员工姓名和工资
select last_name, salary from employees where salary > 12000;
2、查询员工号为176 的员工的姓名和部门号和年薪
select employee_id, last_name, department_id, salary * 12*(1+IFNULL(commission_pct,0)) as 年薪 FROM employees where employee_id = 176;
3、选择工资不在5000 到12000 的员工的姓名和工资
select last_name, salary, from employees where not (salary between 5000 and 1200);
4、选择在20 或50 号部门工作的员工姓名和部门号
select last_name, department_id from employees where #department_id in (20,50); department_id = 20 or department_id= 50;
5、选择公司中没有管理者的员工姓名及 job_id
select last_name, job_id from employees WHERE manager_id is null;
6、选择公司中有奖金的员工姓名,工资和奖金级别
select last_name, salary, commission_pct from employees where commission_pct is not null;
7、选择员工姓名的第三个字母是 a 的员工姓名
select * from (select CONCAT(first_name,last_name) as 姓名 from employees) T where T.姓名 like '__a%';
8、选择姓名中有字母 a 和 e 的员工姓名
SELECT last_name from employees where last_name like '%a%' and last_name like '%e%' ;
9、显示出表employees 表中 first_name 以 'e'结尾的员工信息
SELECT first_name from employees where first_name like '%e';
10、显示出表employees 部门编号在80-100 之间 的姓名、职位
select last_name, job_id, department_id from employees where department_id between 80 and 100;
11、显示出表employees 的manager_id 是 100,101,110 的员工姓名、职位
select last_name, job_id, manager_id from employees where manager_id in(100,101,110);
12、查询没有奖金,且工资小于18000的salary,last_name
select salary, last_name from employees where commission_pct is null and salary < 18000;
13、查询job_id不为'IT' 或者 工资为12000的员工信息;
select * from employees where job_id <> 'IT' or salary = 12000;