gpt4 book ai didi

一个字段内的 MySQL 查询出现次数

转载 作者:行者123 更新时间:2023-11-29 03:12:20 34 4
gpt4 key购买 nike

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

是这样的:SELECT * FROM b_orders where invoice_notes has "Credit Card Declined"< 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)

关于一个字段内的 MySQL 查询出现次数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6130491/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com