在Oracle中用Scott方案
下的emp和dept表
查询 各个部门的部门编号、部门名称以及在1981年入职的职工人数。select deptno 编号, count(*) 人数 from emp where extract(year from hiredate)=1981 group by deptno; -----1
select deptno 编号,dname 名称 from dept; ----2select d.deptno 部门编号,d.dname 部门名称, count(*)人数
from dept d,emp e
where extract(year from hiredate)=1981
group by d.deptno,d.dname ,e.deptno; -------3第一句正确得到职工人数
第二句查询得到部门编号和部门名称但是我要的是这2句的结合版本
第三句查出来的数据很乱 也不是我要的结果
请高手指教 精通Oracle的给修改一下第三句代码 谢谢!
下的emp和dept表
查询 各个部门的部门编号、部门名称以及在1981年入职的职工人数。select deptno 编号, count(*) 人数 from emp where extract(year from hiredate)=1981 group by deptno; -----1
select deptno 编号,dname 名称 from dept; ----2select d.deptno 部门编号,d.dname 部门名称, count(*)人数
from dept d,emp e
where extract(year from hiredate)=1981
group by d.deptno,d.dname ,e.deptno; -------3第一句正确得到职工人数
第二句查询得到部门编号和部门名称但是我要的是这2句的结合版本
第三句查出来的数据很乱 也不是我要的结果
请高手指教 精通Oracle的给修改一下第三句代码 谢谢!
from dept d,emp e
where d.deptno=e.deptno
and extract(year from e.hiredate)=1981
group by d.deptno,d.dname
;
select d.deptno 部门编号,d.dname 部门名称, count(*)人数
from dept d,emp e
where extract(year from hiredate)='1981' and e.deptno=d.deptno
group by d.deptno,d.dname
from dept d,emp e
where extract(year from e.hiredate)=1981
and d.deptno=e.deptno(+)
group by d.deptno,d.dname ;
from dept d left outer join
(select * from emp where extract(year from hiredate)=1981)e
on d.deptno=e.deptno group by d.deptno,d.dname;