Mysql count occurrences of a special character in a field

I want to count all occurrences of the @ symbol in the field, and initially I thought that LIKE '% @%' would be a way, but if the symbol appears in the field more than once this is considered only one.

What other method that I could use would count every event?

Thanks.

EDIT For those who need this, this is what I ended up using, what 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; 
+4
source share
1 answer
 select length('aa:bb:cc:dd')-length(replace('aa:bb:cc:dd',':','')); 

source: http://lists.mysql.com/mysql/215049

+4
source

Source: https://habr.com/ru/post/1484453/


All Articles