Reputation: 1
SELECT Top 5*
FROM (
select
SUM(CASE WHEN Medal = 'Gold' THEN 1 ELSE 0 END) AS 'Gold_Medals',
Country_Code
from olympic_medals
GROUP BY Country_Code
ORDER BY Gold_Medals DESC)
ERROR:
The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP, OFFSET or FOR XML is also specified.
Upvotes: 0
Views: 34
Reputation: 204766
No need for a subquery
select top 5 SUM(CASE WHEN Medal = 'Gold' THEN 1 ELSE 0 END) AS 'Gold_Medals',
Country_Code
from olympic_medals
GROUP BY Country_Code
ORDER BY Gold_Medals DESC
Upvotes: 1