2019.9.3 MySQL 作业~
use test;
select * from emp;
-- 单表查询练习
-- 1.查询基本工资大于1500的员工信息
select * from emp where sal>1500;
-- 2.查询员工姓名不以S开头的任意长度的员工信息
select * from emp where ename not like \'s%\';
-- 3.查询comm不等于0的员工信息
select * from emp where comm!=0;
-- 4.查询每位员工的年薪
select ename, (sal+ifnull(comm,0))*12 as 年薪 from emp;
-- 5.查询各部门的员工数
select count(empno), deptno from emp group by deptno;
-- 6.查询各部门不同职位的人数
select count(empno), job, deptno from emp group by deptno, job;
-- 7.查询平均工资在2000元以上的职位信息,并按照平均工资的降序显示
select job,avg(sal) as 平均工资 from emp group by job having avg(sal)>2000 order by avg(sal) desc;
-- 8.查询最后入职的5位员工
select ename,hiredate from emp order by hiredate desc limit 5;
-- 9.查询员工姓名、入职日期和试用截止日期
select ename, hiredate, adddate(hiredate, interval 1 year) as 试用截止日期 from emp;
-- 10.查询上层管理者工号及其对应的下属员工姓名
select group_concat(ename) as 下属姓名, mgr as 上层管理者工号 from emp group by mgr;