SQL复杂查询 高级问题 超高分悬赏

来源:百度知道 编辑:UC知道 时间:2024/05/31 08:15:47
有一个表(anjian),其中有一个BZ字段,作用是结案与否.
BZ 的内容为 "结案"或"私了"或"无责任"表示已结案.
其它的情况包括NULL,字段为空均视为未结案.

要求一条SQL语句查询出全部未结案记录.

我这样写为什么不行呢?
select * from anjian where bz is null or len(bz)=0 or (bz not like '%结案%' and bz not like '%私了%' and bz not like '%无责任%');

结果查询出来的记录不对.其中居然有BZ的值为结案的情况出来,
这是为什么呢???

我想知道这样行不
select *
from anjian
where bz != '结案' and bz != '私了' and '无责任'

select *
from anjian
where bz != '结案' and bz != '私了' and bz !='无责任'

select * from anjian where bz not in ('结案','私了','无责任')
这个肯定可以,嘿嘿

select * from anjian where Bz is null

或者

select * from anjian where isnull(Bz,未结案)='未结案'