/ /フィールド内のMySQLクエリの実行 - mysql、sql

フィールド内のMySQLクエリの実行 - mysql、sql

テーブルにinvoice_notesというフィールドがありますb_ordersと呼ばれる。このフィールドでは、カードが拒否された回数に応じて「クレジットカードが辞退」という言葉が数回表示されます。私は、「クレジットカードが辞退しました」というフレーズが4回未満のレコードのみを選択するためのクエリを作成しようとしていますか?

このようなもの: SELECT * FROM b_ordersここで、invoice_notesには "Credit Card Declined" <4 "

どんな助けもありがとうございます。 ありがとう

回答:

回答№1は1

これは答えのように聞こえる: http://pisceansheart.wordpress.com/2008/04/15/count-occurrence-of-character-in-a-string-using-mysql/
見積もり:

1. Counting the number of characters in the original string
2. Temporarily ‘deleting’ the character you want to count and count the string again
3. Subtract the first count from the second to get the number of occurrences

SELECT LENGTH("foobarfoobarfoobar") - LENGTH(REPLACE("foobarfoobarfoobar", "b", "")) AS occurrences

具体的な例:

SELECT * FROM b_orders where (length(invoice_notes) - length(replace(invoice_notes, "Credit Card Declined"))) < (length("Credit Card Declined") * 4)

回答№2の場合は0

どのように何かのように:

SELECT * FROM b_orders
WHERE invoice_notes LIKE "%Credit Card Declined%"
AND invoice_notes NOT LIKE "%Credit Card Declined%Credit Card Declined%Credit Card Declined%Credit Card Declined%"

回答№3の場合は0
SELECT * FROM b_orders WHERE invoice_notes LIKE "%Credit Card Declined%"
AND invoice_notes NOT LIKE REPEAT("%Credit Card Declined%",4);