SQL查询--列出至少有一个员工的部门

来源:互联网 发布:mac 如何转换flac ape 编辑:程序博客网 时间:2024/06/16 21:48

请先查看解决问题所需的数据表结构:点击跳转


问题:列出至少有一个员工的部门


答案:

解法一:

select dname from dept where deptno in(select deptno from emp);


解法二:

select dname from dept where deptno in (select deptno from emp group by deptno having count(deptno)>=1);


解法三:

select dname from dept A where exists(select null from emp  B where B.deptno=A.deptno);

0 0