Count number of occurances in mysql
MySQL doesn't have any built in function to count number of occurrences of word in a string, so we need bit of tweak in our query to make this work.
In short, this is what following query will do:
Example:
This example will count no of occurances of "mysql" in a row:
Result will look like this:
In short, this is what following query will do:
occurances = total length of the given word in the string / length of given word
Example:
This example will count no of occurances of "mysql" in a row:
SELECT descrp, ROUND ( ( LENGTH(descp) - LENGTH( REPLACE ( descp, "mysql", "") ) ) / LENGTH("mysql") ) AS count FROM table WHERE id=1;
Result will look like this:
Comments (0)