开发者

How do I create this Select Statement?

There are two tables: emplo开发者_JAVA百科yee and department. Employee table has columns: empid, deptid, employeename Departmen table has: deptid, deptname

I want to create a select statment which will list all employees who are part of department having more than 3 employees.

How do I do that?


select empid, employeename
from Employee
where deptid in (
    select deptid
    from Employee
    group by deptid
    having count(*) > 3
)


Just another approach...

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)
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜