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
)