Why does changing lines matter in some cases but don't in some others?

https://www.codecademy.com/paths/data-science/tracks/sql-intermediate/modules/dspath-sql-aggregates/lessons/codeflix/exercises/sum2

In this exercise,

SELECT user_id,
SUM(watch_duration_in_minutes) AS ‘total_duration’
FROM watch_history
GROUP BY user_id
HAVING total_duration > 400;

works, while

SELECT user_id, SUM(watch_duration_in_minutes) AS ‘total_duration’
FROM watch_history
GROUP BY user_id
HAVING total_duration > 400;

does not.

Why does it matter to separate the lines here, and when does it matter? I noticed that the line change matters when using the CASE as well. It would be helpful to understand the circumstances that require pressing enter.