全球主机交流论坛

标题: 请教一个mysql查询的问题,有没有 “除……之外” 的写法? [打印本页]

作者: gdtv    时间: 2022-5-21 20:36
标题: 请教一个mysql查询的问题,有没有 “除……之外” 的写法?
本帖最后由 gdtv 于 2022-5-21 20:46 编辑

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

我有一个查询条件(语句):
  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 ) 这样写就可以了
作者: 菜单    时间: 2022-5-21 20:37
我没有办法
作者: zxxx    时间: 2022-5-21 20:52
好像就是 not ( condition ) 这样写就可以了

测试了,确实可以这样写。
作者: endenny    时间: 2022-5-21 20:57
印象深刻 not  null
作者: gdtv    时间: 2022-5-21 21:06
zxxx 发表于 2022-5-21 20:52
测试了,确实可以这样写。

嗯,谢谢大佬
作者: Eric.c    时间: 2022-5-21 21:08
not exist 比not in好




欢迎光临 全球主机交流论坛 (https://loc.010206.xyz/) Powered by Discuz! X3.4