如何解决字段中的MySQL查询发生率
| 我在名为b_orders的表中有一个名为invoice_notes的字段。在此字段中,“信用卡被拒绝”字样会显示几次,具体取决于信用卡被拒绝的次数。我正在尝试编写查询以仅选择短语“信用卡被拒绝”出现少于4次的记录? 像这样: SELECT * FROM b_orders,其中invoice_notes的信用卡被拒绝\“ <4 \” 任何帮助表示赞赏。 谢谢解决方法
这听起来像答案: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)
,怎么样:
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%\"
,SELECT * FROM b_orders WHERE invoice_notes LIKE \'%Credit Card Declined%\'
AND invoice_notes NOT LIKE REPEAT(\'%Credit Card Declined%\',4);
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。