Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Subqueries may be used in the FROM clause of a SELECT statement. In the following query, we find the average of the sums of the population of each continent:
mysql> SELECT AVG(cont_sum) -> FROM (SELECT Continent, SUM(Population) AS cont_sum -> FROM Country -> GROUP BY Continent -> ) AS t; +----------------+ | AVG(cont_sum) | +----------------+ | 868392778.5714 | +----------------+