Oracle 练习
1. 题目
查询出 KING 所在部门的部门号、部门名称、部门人数
2. 实例
select d.deptno, d.dname, t.人数
from dept d, (
select count(*) 人数, deptno
from emp
where deptno in (
select deptno
from emp
where ename = 'KING'
)
group by deptno
) t
where d.deptno = t.deptno;
select d.dname, d.deptno, t2.*
from dept d,(
select t.人数, t.deptno
from (
select count(*) 人数,deptno
from emp
group by deptno
) t
where t.deptno in (
select deptno
from emp
where ename = 'KING'
)
) t2
where d.deptno = t2.deptno;
select e.deptno 部门号, d.dname 部门名称, (
select count(*)
from (
select deptno
from emp
where deptno in (
select deptno
from emp
where ename = 'KING'
)
)
) 人数
from emp e, dept d
where e.deptno = d.deptno
and e.ename = 'KING';