求一查询语句
表jobs,内容如下:
userid class
1 0
2 1
3 0
2 0
1 1
class字段只有0和1两个值
请问下如何查出class的值只有0的userid
------解决方案--------------------select * from jobs j where not exists (select 1 from jobs where userid=j.userid And class!=0)
------解决方案--------------------SELECT a4.* from (a a1 left join a a2 on (a1.userid=a2.userid and a1.class=1) ) right join a a4
on a1.userid=a4.userid where a1.userid is null
------解决方案--------------------呵呵,我给你一个效率最高的查询吧,不过只是针对你的说法来的
select userid ,sum (class)
from jobs
group by userid
having sum (class)=0
这个虽然效率一般,但是相对前几种应该最差的
------解决方案--------------------select * from jobs j where not exists (select 1 from jobs where userid=j.userid And class=1)