开发者

How do I get the average string length in mysql?

开发者 https://www.devze.com 2023-01-30 14:30 出处:网络
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

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消