有两个表:员工和部门。 Employee表有列:empid,deptid,employeename Departmen表有:deptid,deptname
我想创建一个选择状态,列出所有员工人数超过3人的员工。
我该怎么做?
答案 0 :(得分:3)
select empid, employeename
from Employee
where deptid in (
select deptid
from Employee
group by deptid
having count(*) > 3
)
答案 1 :(得分:1)
只是另一种方法......
Select e.empid, e.employeename
from employee e
where 3 <= (select count(e2.empid)
from employee e2
where e2.empid <> e.empid and e2.deptid = e.deptid)