在纽约工作的人中,谁的工资最高
select ename from emp
where sal=(select max(e.sal) from emp e join dept d on e.deptno=d.deptno where d.loc='NEW YORK');
查询每个部门下有多少员工
select d.dname,count(e.deptno) from dept d left join emp e on(e.deptno=d.deptno) group by d.dname;
查询除去 salesman 所有平均工资超过 1500 的部门
select e.job,avg(e.sal) from dept d join emp e on(e.deptno=d.deptno)
where e.sal>1500 group by e.job;
查询在 new york 工作的所有员工的姓名,部门名称和工资信息
select e.ename,d.dname,e.sal from dept d join emp e on(d.deptno=e.deptno) where d.loc='NEW YORK';
查询姓名为 King 的员工的编号,名称跟部门
select e.empno,e.ename,d.dname from dept d join emp e on(d.deptno=e.deptno) where e.ename='KING';
查询各种工作的最低工资
select job,min(sal) from emp group by job;
查询工龄大于10年的所有员工信息
select * from emp where (sysdate-hiredate)/365.0>36;
查询每个部门员工数量,平均工资和平均工作年限
select d.dname,count(e.deptno),avg(e.sal),avg((sysdate-hiredate)/365.0) from dept d left join emp e
on(d.deptno=e.deptno)
group by d.dname
统计各部门每个工种的人数,平均工资。
select job,count(*),avg(sal) from emp group by job;
查询从事同一种工作但不属于同一部门的员工信息。
select e.*,e2.* from emp e cross join emp e2
where e.job=e2.job and e.deptno!=e2.deptno
查询所有员工工资都大于1000的部门的信息及员工信息
select d.dname, e.* from emp e join dept d
on(e.deptno=d.deptno)
where d.deptno=(select deptno from emp group by deptno having min(sal)>1000)
查询入职日期早于其直接上级的所有员工信息。
select e.* from emp e,emp d where e.mgr=d.empno and months_between(e.hiredate,d.hiredate)<0
列出雇员中(除去mgr为空的人)工资第二高的人。
select * from(select * from (select * from (select * from emp where job<>'persident' and mgr is not null order by sal desc) where rownum<3) order by sal) where rownum=1;
列出1981年来公司所有员工的总收入(包括sal和comm)
select ename from emp
where sal=(select max(e.sal) from emp e join dept d on e.deptno=d.deptno where d.loc='NEW YORK');
查询每个部门下有多少员工
select d.dname,count(e.deptno) from dept d left join emp e on(e.deptno=d.deptno) group by d.dname;
查询除去 salesman 所有平均工资超过 1500 的部门
select e.job,avg(e.sal) from dept d join emp e on(e.deptno=d.deptno)
where e.sal>1500 group by e.job;
查询在 new york 工作的所有员工的姓名,部门名称和工资信息
select e.ename,d.dname,e.sal from dept d join emp e on(d.deptno=e.deptno) where d.loc='NEW YORK';
查询姓名为 King 的员工的编号,名称跟部门
select e.empno,e.ename,d.dname from dept d join emp e on(d.deptno=e.deptno) where e.ename='KING';
查询各种工作的最低工资
select job,min(sal) from emp group by job;
查询工龄大于10年的所有员工信息
select * from emp where (sysdate-hiredate)/365.0>36;
查询每个部门员工数量,平均工资和平均工作年限
select d.dname,count(e.deptno),avg(e.sal),avg((sysdate-hiredate)/365.0) from dept d left join emp e
on(d.deptno=e.deptno)
group by d.dname
统计各部门每个工种的人数,平均工资。
select job,count(*),avg(sal) from emp group by job;
查询从事同一种工作但不属于同一部门的员工信息。
select e.*,e2.* from emp e cross join emp e2
where e.job=e2.job and e.deptno!=e2.deptno
查询所有员工工资都大于1000的部门的信息及员工信息
select d.dname, e.* from emp e join dept d
on(e.deptno=d.deptno)
where d.deptno=(select deptno from emp group by deptno having min(sal)>1000)
查询入职日期早于其直接上级的所有员工信息。
select e.* from emp e,emp d where e.mgr=d.empno and months_between(e.hiredate,d.hiredate)<0
列出雇员中(除去mgr为空的人)工资第二高的人。
select * from(select * from (select * from (select * from emp where job<>'persident' and mgr is not null order by sal desc) where rownum<3) order by sal) where rownum=1;
列出1981年来公司所有员工的总收入(包括sal和comm)
select sum(sal)+sum(comm) from emp where to_char(hiredate,'yyyy')='1981';
如有老铁觉得错误或者需要改正的地方请留言!!!