select * from dept, (select deptno from emp) b where a.deptno =b.deptno
select distinct emp.deptno from emp join dept on emp.deptno=dept.deptno; 经过验证哈,自己再试试。
如果只要显示部门号,只要: select deptno from emp group by deptno having count(*) > 0 order by deptno; 如果要显示部门信息,这么写: select d.deptno, d.dname, d.loc from dept d, emp e where d.deptno = e.deptno group by d.deptno, d.dname, d.loc having count(e.empno) > 0 order by d.deptno;
如果只要显示部门号,只要: select deptno from emp group by deptno having count(*) > 0 order by deptno; 如果要显示部门信息,这么写: select d.deptno, d.dname, d.loc from dept d, emp e where d.deptno = e.deptno group by d.deptno, d.dname, d.loc having count(e.empno) > 0 order by d.deptno;
经过验证哈,自己再试试。
select deptno from emp
group by deptno
having count(*) > 0
order by deptno;
如果要显示部门信息,这么写:
select d.deptno, d.dname, d.loc
from dept d, emp e
where d.deptno = e.deptno
group by d.deptno, d.dname, d.loc
having count(e.empno) > 0
order by d.deptno;
select deptno from emp
group by deptno
having count(*) > 0
order by deptno;
如果要显示部门信息,这么写:
select d.deptno, d.dname, d.loc
from dept d, emp e
where d.deptno = e.deptno
group by d.deptno, d.dname, d.loc
having count(e.empno) > 0
order by d.deptno;