Use of GROUP BY in SQL

Viewed 40

QUESTION: Which release_year had the most language diversity?

HINT: Most language diversity" can be interpreted as COUNT(DISTINCT ___).

id title release_year country duration language certification gross budget
1 Intolerance: Love's Struggle Throughout the Ages 1916 USA 123 null not rated null 385907
2 Over the Hill to the Poorhouse 1915 Germany 523 german rated null 385907

These are the fields given. How can I get the release_year in which there is the maximum language diversity?

SELECT COUNT(DISTINCT release_year)
FROM films
GROUP BY release_year
1 Answers
SELECT TOP 1 *
FROM (
    SELECT 
        release_year,
        COUNT(DISTINCT language) cnt
    FROM films
    GROUP BY release_year
) t1
ORDER BY cnt DESC
Related