How do I get the average string length in mysql?
This:
SELECT AVG(LENGTH(string))
FROM BLAH
LIMIT 10;
...seems to grind through all results. If I take off the AVG, it's way faster. Is it best to create a subquery like
SELECT AVG(len)
FROM (SELECT LENGTH(string) as len
FROM BLAH
LIMIT 10) as herp
This also seems slow. I don't want to load it all into php loop through with开发者_如何学Python strlen. I was hoping there was a memory efficient solution.
the first query loops through all the rows in the table (the limit 10 doest limit anything, since there will always be only 1 row returned)
the second query avg's rows 1 to 10
what kind of average are you looking for?
精彩评论