My database teacher asked me to write (on Oracle Server) a query: select the groupid with the highest score average for year 2010
I wrote:
SELECT * FROM (
SELECT groupid, AVG(score) average FROM points
WHERE yr = 2010
AND score IS NOT NULL
GROUP BY groupid
ORDER BY average DESC
) WHERE rownum = 1;
My teacher tells me that this request is "better":
SELECT groupid, AVG(score) average FROM points
WHERE yr = 2010
GROUP BY groupid
HAVING AVG(score) >= ALL (
SELECT AVG(score) FROM points
WHERE yr = 2010
GROUP BY groupid
);
Which one is the fastest/better ? Is there any better solution too (for Oracle only) ? Thanks.