LIKE と NOT LIKE を一緒に使用する際に助けが必要です...別のサーバーからのリクエスト変数に基づいて WHERE 句を渡すクエリがあります。クエリの 1 つは次のようなものです。
'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) "