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 strlen. I was hoping there was a memory efficient solution.
MySQL LENGTH() Function The LENGTH() function returns the length of a string (in bytes).
You use the DISTINCT operator in the AVG function to calculate the average value of the distinct values. For example, if you have a set of values 1,1,2,3, the AVG function with DISTINCT operator will return 2 i.e., (1 + 2 + 3) / 3 .
MySQL CHAR_LENGTH() function MySQL CHAR_LENGTH() returns the length (how many characters are there) of a given string. The function simply counts the number characters and ignore whether the character(s) are single-byte or multi-byte.
What's the LEN() Equivalent in MySQL? In SQL Server, you can use the LEN() function to return the number of characters in a string. This is a Transact-SQL function that can also be used in Azure databases. In MySQL, you need to use the CHAR_LENGTH() function.
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?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With