首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Mysql >

求一查询语句,该如何解决

2012-05-08 
求一查询语句表jobs,内容如下:useridclass1021302011class字段只有0和1两个值请问下如何查出class的值只有

求一查询语句
表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)

热点排行