It's been a while since i used MySQL but would something like this work?
SELECT ColumnName, COUNT(ColumnName) AS ColumnName_Count
FROM table_name
GROUP BY ColumnName
ORDER BY ColumnName_Count DESC;
Loop through the rows - explode the sentence into words - increment an associative array of the words. At the end you'll have an array of all the words and their count.
SELECT
COUNT(*) as num,
SUBSTRING_INDEX(SUBSTRING_INDEX(logs.useragent, ' ', numbers.n), ' ', -1) logs
FROM
(SELECT 1 n UNION ALL SELECT 2
UNION ALL SELECT 3 UNION ALL SELECT 4) numbers INNER JOIN logs
ON CHAR_LENGTH(logs.useragent)-CHAR_LENGTH(REPLACE(logs.useragent, ' ', '')) >= numbers.n-1
GROUP BY logs
ORDER BY num DESC
LIMIT 20;
+-------+-----------------------------------------+
| num | logs |
+-------+-----------------------------------------+
| 38314 | Mozilla/5.0 |
| 17251 | (compatible; |
| 12233 | NT |
| 12211 | (Windows |
| 7452 | MSIE |
| 6167 | 6.1; |
| 5831 | U; |
| 5718 | Mozilla/4.0 |
| 5379 | Linux |
| 5367 | (X11; |
| 4365 | Windows |
| 4355 | (Windows; |
| 4014 | Googlebot/2.1; |
| 4007 | +http://www.google.com/bot.html) |
| 3822 | x86_64) |
| 3581 | Stratagems |
| 3581 | Kumo |
| 3205 | |
| 2821 | http://www.nominet.org.uk/privacypolicy |
| 2803 | (Macintosh; |
+-------+-----------------------------------------+
We use essential cookies to make this site work, and optional cookies to enhance your experience.