微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

字段中的MySQL查询发生率

如何解决字段中的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 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?