请教一个mysql查询的问题,有没有 “除……之外” 的写法?

73次阅读

共计 455 个字符,预计需要花费 2 分钟才能阅读完成。

有点复杂,不知能不能表达清楚。

我有一个查询条件 (语句):

  1. condition = ” field1>0 and field2>0 and field3>0 “

复制代码

这一条语句不能动,我想查询满足以上条件之外的所有结果,该怎么写呢?

有没有类似的语句:

  1. selec t * from xxx where not (condition)

复制代码

这样的写法?

当然可以改写成这样:

  1. selec t * from xxx where  field1<=0 or field2<=0 or field3<=0

复制代码

这样可以获得正确的结果。
但是如果我想不变动 condition 这一个语句,有办法吗?

也不想用这种方法:

  1. selec t * from xxx where id not in (selec t id from xxx where condition)

复制代码

————————–

更新:好像就是 not (condition) 这样写就可以了

网友回复:

注册 我没有办法

gdtv 测试了,确实可以这样写。

菜单 印象深刻 not  null

zxxx 嗯,谢谢大佬

endenny not exist 比 not in 好

正文完
 0