'SQL - Why does the GROUP BY clause cause a difference in my result?

I'm learning SQL on Datacamp and I run into this question:

In how many different years were more than 200 movies released?

The answer to it is 13.

Here is my solution which produces the wrong answer: 91

SELECT count(distinct release_year)
FROM films
HAVING count(title) > 200;

I got the right answer when I changed a code a bit as below:

SELECT count(distinct release_year)
FROM films
GROUP BY release_year
HAVING count(title) > 200;

Could anyone please help explain why adding the GROUP BY clause can cause this change. I learn that GROUP BY helps group the results and only affects how the result table displays.

Thank you so much.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source