求一条sql语句
数据库表名 employee 结构如下;
id employeeid flag
1 x 0
2 x 1
3 y 0
4 z 1
5 m 0
6 n 0
查询出表中只有flag=0的employeeid,结果应该为:
id employeeid flag
3 y 0
5 m 0
6 n 0
请问大家 sql语句怎么写啊?效率越高越好
------解决方案--------------------select id, exployeeID, flag
from employee
where id not in(select id from employee where flag <> 0)
------解决方案--------------------select
em.id,
em.exployeeID,
em.flag
from
employee em
where
not exists(
select
null
from
employee ep
where
ep.exployeeID = em.exployeeID
and ep.flag = 0)
------解决方案--------------------select id, employeeid, flag
from employee
where flag= '0 ' and employeeid not in (select employeeid from employee where flag <> '0 ')
------解决方案--------------------select * from employee where employeeid in(select employeeid from employee where flag= '0 ' group by employeeid having count(*)=1)
------解决方案--------------------select id, employeeID, flag
from employee emp
where not exists (select 1 from employee where employeeid=emp.employeeid and flag <> 0);
------解决方案--------------------这个我试过,可以。呵呵