gpt4 book ai didi

php - MySQL 和 PHP - 使用 'LIKE' 和 'NOT LIKE'

转载 作者:行者123 更新时间:2023-11-29 00:31:02 25 4
gpt4 key购买 nike

我需要一些帮助来同时使用 LIKE 和 NOT LIKE...我有一个查询,我根据我的请求变量来自另一台服务器来传递 WHERE 子句。其中一个查询如下所示:

    'CONNECT' =>
"( detail_head.comment LIKE '%port%'
or detail_head.comment LIKE '%forward%'
or detail_head.comment LIKE '%connect%'
or detail_head.comment LIKE '%router%'
or detail_head.comment LIKE '%fire%wall%'
or detail_head.comment LIKE '%sonic%'
) AND (
detail_head.comment NOT LIKE '%report%'
OR detail_head.comment NOT LIKE '%portal%'
)",

你可以看到我使用的是 LIKE 和 NOT LIKE。不幸的是,这并没有像我希望的那样工作。我猜这是因为我要的是 PORT,而不是 REPORT,所以无论如何它都会给我 LIKE。

遇到这种情况我该怎么办?我正在考虑制作另一个查询或数组,我将用作“排除列表”。如果查询是 LIKE 语句,我可以在我的 WHERE 子句中使用它来表示“table_uid NOT IN(LIST OF COMMA SEPARATED UIDs)”。

我有我想要排除的 LIKE 语句:

$exclude_where_clauses = array(
'CC' => "(detail_head.comment LIKE '%ccb%') ",
'CONNECT' => "(detail_head.comment LIKE '%report%' OR detail_head.comment LIKE '%portal%') ",
'EO' => "(detail_head.comment LIKE '%OCU%' AND detail_head.comment LIKE '%KS%' AND detail_head.comment LIKE '%screen%' AND detail_head.comment LIKE '%term%') ",
'INVENTORY' => "(detail_head.comment LIKE '%discount%') ",
'KS' => "(detail_head.comment LIKE '%panel%' or detail_head.comment LIKE '%PMIX%' or detail_head.comment LIKE '%pmix%') ",
'OCUS' => "(detail_head.comment LIKE '%document%') ",
'SALES' => "(detail_head.comment LIKE '%point%') ",
'SECURITY' => "(detail_head.comment LIKE '%km%') ",
'TERMS' => "(detail_head.comment LIKE '%forward%' or detail_head.comment LIKE '%sales%' or detail_head.comment LIKE '%intermittent%' or detail_head.comment LIKE '%print%' or detail_head.comment LIKE '%de%min%' or detail_head.comment LIKE '%reciept%' or detail_head.comment LIKE '%time%') ",
);

所以,最后,我想将我当前的查询数组转换为 "(detail_head.comment LIKE '%port%' or detail_head.comment LIKE '%forward%' or detail_head. comment LIKE '%connect%' or detail_head.comment LIKE '%router%' or detail_head.comment LIKE '%fire%wall%' or detail_head.comment LIKE '%sonic%') AND table_uid NOT IN (LIST OF COMMA SEPARATED UIDs ) "

最佳答案

试试这个:

'CONNECT' => "
( detail_head.comment LIKE '%port%'
OR detail_head.comment LIKE '%forward%'
OR detail_head.comment LIKE '%connect%'
OR detail_head.comment LIKE '%router%'
OR detail_head.comment LIKE '%fire%wall%'
OR detail_head.comment LIKE '%sonic%'
)
AND NOT (
detail_head.comment LIKE '%ccb%'
OR detail_head.comment LIKE '%report%'
OR detail_head.comment LIKE '%portal%'
OR detail_head.comment LIKE '%OCU%'
OR detail_head.comment LIKE '%KS%'
OR detail_head.comment LIKE '%screen%'
OR detail_head.comment LIKE '%term%'
OR detail_head.comment LIKE '%discount%'
OR detail_head.comment LIKE '%panel%'
OR detail_head.comment LIKE '%PMIX%'
OR detail_head.comment LIKE '%pmix%'
OR detail_head.comment LIKE '%document%'
OR detail_head.comment LIKE '%point%'
OR detail_head.comment LIKE '%km%'
OR detail_head.comment LIKE '%forward%'
OR detail_head.comment LIKE '%sales%'
OR detail_head.comment LIKE '%intermittent%'
OR detail_head.comment LIKE '%print%'
OR detail_head.comment LIKE '%de%min%'
OR detail_head.comment LIKE '%reciept%'
OR detail_head.comment LIKE '%time%'
)
",

关于php - MySQL 和 PHP - 使用 'LIKE' 和 'NOT LIKE',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16523389/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com