在做“少于等于3个人的部门信息”这道题时,我用如下语句:
select * from dept where deptno= (select deptno from emp group by deptno having count(*)<=3);
会产生如下错误:
Subquery returns more than 1 row
上网查阅资料才知道,子查询的查询结果应只有一行
我们可以将语句改为如下模式:
select name from tabel1 where id = any(select id from tabel2)
所以该题语句改为如下语句:
select * from dept where deptno=any(select deptno from emp group by deptno having count(*)<=3);
这样就不会报错了。