Saturday, February 15, 2020

MySQL Count the number of occurrences / number of existance of a string in a text field

SET @search = "pri";
SELECT  details,    
ROUND((LENGTH(details) - LENGTH( 
REPLACE ( details, LOWER(@search), ""))) / LENGTH(@search)) AS count    
FROM user_search_index
ORDER BY COUNT desc

No comments:

Post a Comment