Currently I'm working with a database on phpmyadmin. I'm trying to find the Average of an SQL statement that is implementing a LIMIT code.
SQL Statement -
SELECT avg(value) FROM que LIMIT 10
The problem with the code is its not averaging the first 10 numbers in value column, but all of them. So the LIMIT 10 isn't actually working. Is there anyway to avoid this or an alternative?
You need to use a subquery:
SELECT avg(value)
FROM (select value
from que
LIMIT 10
) q;
Do note, however, that use of limit
without an order by
produces arbitrary results -- there is no definition of the "first ten" records in a table.
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