Supposed I have the following tables:
Sailor(sid, sname, age)
Boat(bid, sid)
Each boat can have many sailors, and each individual sailor can serve on many boats. What I want to do is to find the boat with the highest average age of sailors.
I can find the average age of the sailor on each boat with this subquery:
SELECT b.bid, AVG(s.age) AS avg_age FROM sailor s, boat b
WHERE b.sid = s.sid
GROUP BY b.bid
However, I am stuck on how to find the maximum row from this subquery further on.
P.S. I'm also looking for MySQL-compatible query, if that makes any difference.