number          phone
123 15211111111
124 0
124 15311111111
125 0
126 0
126 15511111111
124 15411111111
……                 ……
如果这是一张表的话 怎么样查出number对应的phone只为0的情况 也就是如何查出125的记录

解决方案 »

  1.   

    select number  from 表 where phone=0
      

  2.   

    若是这样的话number存过0也存过其它号码的也会被筛选到,是不符合要求的,需求是只要number对应phone为0的,不能对应过其它非0 的值
      

  3.   

    没测试,大概这意思,用not exists 来筛选
    select number  from 表 a where phone=0 and not exists(select * from 表 b where b.phone <> 0 and a.number=b.number)