MySQL query to get the longest texts that occurr most often
I have a MySQL table t1 a text field f1. I have this query to find the top 100 most common values of f1 along with their frequency:
SELECT COUNT(*) AS c, f1 FRO开发者_C百科M t1 GROUP BY f1 ORDER BY c DESC LIMIT 100;
What I need now is a query to find out what are the longest values of f1 that occur most often. That is, I want to first order the records of the table by frequencies (like the query above does) and then I want to order them by length and grab the top 100. I tried doing that with this query but it doesn't return what I want, it simply returns the records with the longest values of f1 (most of them with only 1 occurrences):
SELECT f1, LENGTH(f1) AS l, COUNT(*) AS c FROM t1 GROUP BY f1, LENGTH(f1) ORDER BY l DESC, c DESC LIMIT 100;
My table has more than 44M records in case that matters.
Thanks.
You said you want to order by the frequency then the length, but you ask for the order by length then frequency. Reverse your ORDER BY
clause.
精彩评论