Sql 如何修改此特定查询? 从foobar中选择* 其中userid!='100'和col1 REGEXP'[[::]' 或用户ID!='100'和col2 REGEXP'[[::]' 或用户ID!='100'和col3 REGEXP'[[::]]
这个问题对我来说很有效。它将根据两个标准进行过滤Sql 如何修改此特定查询? 从foobar中选择* 其中userid!='100'和col1 REGEXP'[[::]' 或用户ID!='100'和col2 REGEXP'[[::]' 或用户ID!='100'和col3 REGEXP'[[::]],sql,mysql,database,Sql,Mysql,Database,这个问题对我来说很有效。它将根据两个标准进行过滤 其中col1或col2或col3具有“测试”和 userid不是100 我还有另一个col4我想要的,除了上述两个条件之外,它必须过滤掉那些col4='y' 我应该如何修改上述查询?如果查询中有错误,需要将第二个col2更改为col3。如果重新格式化代码,则更容易看到错误: SELECT * FROM foobar WHERE userid != '100' AND col1 REGEXP '[[:<:]]test[[:>:]]'
col4
我想要的,除了上述两个条件之外,它必须过滤掉那些col4='y'
我应该如何修改上述查询?如果查询中有错误,需要将第二个
col2
更改为col3
。如果重新格式化代码,则更容易看到错误:
SELECT * FROM foobar
WHERE userid != '100' AND col1 REGEXP '[[:<:]]test[[:>:]]'
OR userid != '100' AND col2 REGEXP '[[:<:]]test[[:>:]]'
OR userid != '100' AND col3 REGEXP '[[:<:]]test[[:>:]]'
选择*
来自foobar
其中userid!='100'
和(col1 REGEXP'[[::]]
或col2 REGEXP“[[::]”
或col3 REGEXP'[[::]]')
还有col4'y'
像这样的东西?您还可以分离出userid!='100'
,因为这是三种检查的共同点
SELECT *
FROM foobar
WHERE userid != '100'
AND (col1 REGEXP '[[:<:]]test[[:>:]]'
OR col2 REGEXP '[[:<:]]test[[:>:]]'
OR col3 REGEXP '[[:<:]]test[[:>:]]')
AND col4 <> 'y'
选择*
来自foobar
其中userid!='100'
和(col1 REGEXP'[[::]]
或col2 REGEXP“[[::]”
或col3 REGEXP'[[::]]')
还有col4!='y'
试试这个:
SELECT *
FROM foobar
WHERE userid != '100'
AND (col1 REGEXP '[[:<:]]test[[:>:]]'
OR col2 REGEXP '[[:<:]]test[[:>:]]'
OR col3 REGEXP '[[:<:]]test[[:>:]]' )
AND col4 != 'y'
选择*
来自foobar
其中col4='y'
或(
用户ID!=“100”
及(
col1 REGEXP'[[::]]
或
col2 REGEXP'[[::]]
或
col2 REGEXP'[[::]]
)
)
从foobar中选择*
(userid!=“100”)和
(col1 REGEXP'[[::]]或userid!=“100”或col2 REGEXP'[[::]]或col2 REGEXP'[[::]]”
还有col4'y'
如果他想用col4='y'过滤结果,那么最后的检查不应该被撤销吗?@Brandon:Jinx。我想我们俩是同时发现的。
SELECT *
FROM foobar
WHERE userid != '100'
AND (col1 REGEXP '[[:<:]]test[[:>:]]'
OR col2 REGEXP '[[:<:]]test[[:>:]]'
OR col3 REGEXP '[[:<:]]test[[:>:]]')
AND col4 <> 'y'
SELECT *
FROM foobar
WHERE userid != '100'
AND (col1 REGEXP '[[:<:]]test[[:>:]]'
OR col2 REGEXP '[[:<:]]test[[:>:]]'
OR col3 REGEXP '[[:<:]]test[[:>:]]' )
AND col4 != 'y'
SELECT *
FROM foobar
WHERE col4 = 'y'
OR (
userid != '100'
AND (
col1 REGEXP '[[:<:]]test[[:>:]]'
OR
col2 REGEXP '[[:<:]]test[[:>:]]'
OR
col2 REGEXP '[[:<:]]test[[:>:]]'
)
)
SELECT * FROM foobar WHERE
(userid != '100') AND
(col1 REGEXP '[[:<:]]test[[:>:]]' OR userid != '100' OR col2 REGEXP '[[:<:]]test[[:>:]]' OR col2 REGEXP '[[:<:]]test[[:>:]]')
AND col4 <> 'y'