MySQL 查询字段内出现的情况

发布于 2024-11-09 11:01:35 字数 238 浏览 0 评论 0原文

我在名为 b_orders 的表中有一个名为 Invoice_notes 的字段。在此字段中,“信用卡被拒绝”字样将出现多次,具体取决于该卡被拒绝的次数。我正在尝试编写一个查询来仅选择短语“Credit Card Declined”出现次数少于 4 次的记录?

像这样的东西: SELECT * FROM b_orders 其中invoice_notes 具有“信用卡被拒绝”< 4 "

如有任何帮助,我们将不胜感激。 谢谢

I have a field called invoice_notes in a table called b_orders. In this field the words "Credit Card Declined" will show up several times depending on how many times the card has been declined. I am trying to write a query to select only the records where the phrase "Credit Card Declined" appears less than 4 times?

Something like this:
SELECT * FROM b_orders where invoice_notes has "Credit Card Declined" < 4 "

Any help is appreciated.
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

蒲公英的约定 2024-11-16 11:01:36

这听起来像答案: 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)

This sounds like the answer: http://pisceansheart.wordpress.com/2008/04/15/count-occurrence-of-character-in-a-string-using-mysql/
Quote:

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  

For your specific example:

SELECT * FROM b_orders where (length(invoice_notes) - length(replace(invoice_notes, 'Credit Card Declined'))) < (length('Credit Card Declined') * 4)
小梨窩很甜 2024-11-16 11:01:36

怎么样:

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

How about something like:

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%"
開玄 2024-11-16 11:01:36
SELECT * FROM b_orders WHERE invoice_notes LIKE '%Credit Card Declined%' 
AND invoice_notes NOT LIKE REPEAT('%Credit Card Declined%',4);
SELECT * FROM b_orders WHERE invoice_notes LIKE '%Credit Card Declined%' 
AND invoice_notes NOT LIKE REPEAT('%Credit Card Declined%',4);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文