mysql计数字段中特殊字符的出现 [英] mysql count occurrences of special character in a field
本文介绍了mysql计数字段中特殊字符的出现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想计算一个字段中所有@符号的出现,最初我想喜欢'%@%',但是如果该字符出现在该字段中则更多不止一次,它仅将其视为一个.
I am wanting to count all occurrences of the @ symbol in a field and originally i thought LIKE '%@%' would be the way to go, but if the character appears in the field more than once it only counts it as one.
我还能使用什么其他方法来计算每次出现的次数?
What other method are there that i could use that would count every occurrence?
谢谢.
编辑 对于任何需要它的人,这就是我最终使用它的目的.
EDIT For anyone needing it, this is what i ended up using that works.
$count = 0;
$sql = mysql_query("SELECT LENGTH(field_name) - LENGTH(REPLACE(field_name,'@','')) AS 'occurs' FROM table_name WHERE field_name LIKE '%@%'");
while ($data = mysql_fetch_assoc($sql)) {
$count += $data['occurs'];
}
echo $count;
推荐答案
select length('aa:bb:cc:dd')-length(replace('aa:bb:cc:dd',':',''));
来源: http://lists.mysql.com/mysql/215049
这篇关于mysql计数字段中特殊字符的出现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文