select * from 表 a where name='aa' and ht='gg'
and exists(select 1 from 表 where a.lnumber-1=lnumber and  ht='gg' and status is not null)

解决方案 »

  1.   

    select * from bb where name='aa' and ht='gg' and lnumber-1=(select lnumber from bb where ht='gg' and status is not null) 原来我是这么写的,不只对否,请指教。你上面的写法比较好。
      

  2.   

    dalinbai(大林) ( ) 信誉:100  2007-07-28 15:43:37  得分: 0  
     
     
       select * from bb where name='aa' and ht='gg' and lnumber-1=(select lnumber from bb where ht='gg' and status is not null) 原来我是这么写的,不只对否,请指教。你上面的写法比较好。
      
     
    --------------
    如果是這樣的話,改用關聯來寫,效率更優。
    Select A.* From bb A 
    Inner Join bb B
    On A.lnumber - 1 = B.lnumber
    Where A.name='aa' and A.ht='gg'
    And B.ht='gg' and B.status is not null
      

  3.   

    select * from bb where name='aa' and ht='gg' and lnumber-1=(select lnumber from bb where ht='gg' and status is not null) 原来我是这么写的,不只对否 不对 lnumber-1=(select lnumber from bb where ht='gg' and status is not null) 
    select lnumber from bb where ht='gg' and status is not null 会返回多条,
     = 换成in
      

  4.   

    SORRY 看错了~是对的~ 鱼儿的比较好,用关联