select deptno, count(*) from EMP group by DEPTNO having count(*) >1
--2
select * from emp where sal > (select sal from emp where ename = 'SMITH')
--3
select e0.ENAME, e1.ename from emp e0, emp e1 where e0.MGR = e1.empno
--4
select e0.*, e1.* from emp e0, emp e1 where e0.mgr = e1.empno(+) and e0.hiredate < e1.hiredate
--5
select d.dname, e.* from dept d, emp e where d.deptno = e.deptno(+)
--6
select e.ename, d.dname from emp e join dept d on e.deptno = d.deptno where job = 'CLERK'
--7
select job from emp group by job having min(sal) > 1500
--8
select e.ename from emp e, dept d where d.dname = 'SALES' and e.deptno(+) = d.deptno
--9
select * from emp where sal > (select avg(sal) from emp)
--10
select * from emp where job = (select job from emp where ename = 'SCOTT')
--11
select * from emp where sal in (select sal from emp where deptno = 30)
--12
select * from emp where sal > all (select sal from emp where deptno = 30)
--13
select count(empno) 人数, avg(sal) 平均工资, avg(EXTRACT(year FROM sysdate) - EXTRACT(year FROM emp.hiredate)) 平均雇佣期限 from dual, emp group by deptno
--14
select e.ename, d.dname, e.sal from emp e, dept d where e.deptno = d.deptno(+)
--15
select d.*, t.count from dept d, (select deptno, count(empno) count from emp group by deptno) t where d.deptno = t.deptno(+)
--16
select job, min(sal) from emp group by job
--17
select deptno, min(sal) from emp where job = 'MANAGER' group by deptno
你登录的是sys用户,emp表是在scott用户下的,在sys用户中要查询scott用户下的emp表,表名称格式如下:用户名.表名称
所以你可以这样查询:
select
*
from
scott.emp
select deptNo from emp group by deptNo having avg(salary)<2000因为where子句不能使用聚合函数,所以可以分组,然后用having来实现
deptNo代表部门号,salary代表工资,看看和您表中的是否一致。不一致修改它们即可,下面也是。
select avg(salary) from emp 查询平均工资
select max(salary) from emp 查询最高工资
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)