1

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) "

4

2 に答える 2

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 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%'
    )
",
于 2013-05-13T17:54:23.097 に答える
0

これがこれ以上効率的であるとは思いません (実際には効率が悪いかもしれません) が、仕様をより健全に定義する方法になる可能性がありますregexp()

これは 0 を返します。

SELECT 'foo report bar' REGEXP '[[:<:]]port[[:>:]]';

これは 1 を返します:

SELECT 'foo report bar' REGEXP '[[:<:]]report[[:>:]]';

MySQL の詳細については、マニュアルを参照してください。(5.1マニュアルリンク)

当面のタスクの性質、およびこれがデータベースサーバーに与える負荷の頻度と頻度に応じて、フィールドまたは関連テーブルを追加して、前もって処理を実行できるようにすることを検討する場合があります (データを挿入するとき)。フルテキスト フィールドで大量のテキスト処理を行う代わりに、事後にこのようなレポートをより軽い方法で実行できます。

于 2013-05-13T15:24:15.510 に答える