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)
and exists(select 1 from 表 where a.lnumber-1=lnumber and ht='gg' and status is not null)
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
select lnumber from bb where ht='gg' and status is not null 会返回多条,
= 换成in