SELECT Temp.rating, Temp.avgage
FROM
( SELECT S.rating, AVG(S.age) AS avgage
FROM Sailors S
GROUP BY S.rating
) AS Temp
WHERE Temp.avgage =
( SELECT MIN (Temp.avgage)
FROM Temp --- the error is here
)
В зависимости от того, как вы хотите обрабатывать галстуки, вы можете просто использовать:
SELECT Temp.rating, Temp.avgage
FROM
( SELECT S.rating, AVG(S.age) AS avgage
FROM Sailors S
GROUP BY S.rating
) AS Temp
ORDER BY Temp.avgage
LIMIT 1
или более простой эквивалент:
SELECT S.rating, AVG(S.age) AS avgage
FROM Sailors S
GROUP BY S.rating
ORDER BY avgage
LIMIT 1
или этот (который показывает все связанные результаты):
SELECT Temp.rating, Temp.avgage
FROM
( SELECT S.rating, AVG(S.age) AS avgage
FROM Sailors S
GROUP BY S.rating
) AS Temp
WHERE Temp.avgage =
( SELECT AVG(S.age) AS avgage
FROM Sailors S
GROUP BY S.rating
ORDER BY avgage
LIMIT 1
)