Count occurrences of a word in string: Difference between revisions

Jump to navigation Jump to search
m
Line 11: Line 11:


SELECT FLOOR((LENGTH(@paragraph) - LENGTH(REPLACE(@paragraph, @term, ''))) / LENGTH(@term)) AS occurrences;
SELECT FLOOR((LENGTH(@paragraph) - LENGTH(REPLACE(@paragraph, @term, ''))) / LENGTH(@term)) AS occurrences;
/* same with the following query */
SELECT FLOOR((CHAR_LENGTH(@paragraph) - CHAR_LENGTH(REPLACE(@paragraph, @term, ''))) / CHAR_LENGTH(@term)) AS occurrences;
</pre>
</pre>
[http://sqlfiddle.com/#!9/6d06f/480/2 online example]


== PHP ==
== PHP ==

Navigation menu