23、列出与"SCOTT"从事相同工作的所有员工及部门名称
Select e.ename, d.dname from emp e join dept d on e.deptno = d.deptno where job = (Select job from emp where ename = 'SCOTT')
第一步 获取部门是30的所有员工薪水
select sal from emp where deptno = 30
第二步 获取结果
Select ename, sal from emp where sal in (select sal from emp where deptno = 30)
select ename, sal, dname from emp e join dept d on e.deptno = d.deptno where sal > (select max (sal) maxSal from emp where deptno = 30)
Select d.dname 部门名称, count(e.empno) 员工数量, round(avg(e.sal), 2) 平均薪水, round(avg(sysdate-hiredate)/365,0) 服务期限 from emp e, dept d where e.deptno = d.deptno group by d.dname
Select ename, dname, sal from emp e, dept d where e.deptno = d.deptno
Select d.*, (select count(e.empno) from emp e where e.deptno = d.deptno) 人数 from dept d
29、列出各种工作的最低工资及从事此工作的雇员姓名
select deptno, min(sal) from (select deptno, sal, empno from emp where empno in (Select distinct mgr from emp where mgr is not null)) group by deptno
select ename 主管, sal 主管工资 from emp where empno in (Select distinct mgr from emp where mgr is not null) and sal > 3000
select deptno from dept where dname like '%S%'
select d.dname, sum(e.sal), count(e.empno) from emp e right join dept d on e.deptno = d.deptno group by d.dname having d.dname like '%S%'
Update emp set sal = sal*1.1 where (months_between(sysdate, hiredate)/12) > 28