Problem with aggregate functions exercise in SQL course (I think it should work with this code, but it doesn´t compile)

In this exercise I am asked to generate a table of user ids and total watch duration for users who watched more than 400 minutes of content.

My code does exactly the same as the solution but mine refers to the columns with numbers (as I’ve done before) in order to avoid having to type their names again. It’s not a big deal but it’s annoying because I think I’m right. Please tell me where I’m wrong, does the ‘HAVING’ clause not support this maneuver?

Thanks.

(It doesn’t let me select SQL Language when creating a Codebyte so I just left the code here)

SELECT user_id, SUM(watch_duration_in_minutes) 

FROM watch_history

     GROUP BY 1

     HAVING 2 > 400

;

I think it’s b/c HAVING is evaluated before the SELECT clause and it doesn’t know what that 2 is in reference to. Also, HAVING filters groups according to the condition(s) applied.

I would avoid using column numbers and just write out the column names in order to avoid any future headaches with data. (ie: what if you add data/columns and then your query doesn’t work).

SELECT user_id, 
	SUM(watch_duration_in_minutes)
FROM watch_history
GROUP BY user_id
HAVING SUM(watch_duration_in_minutes) > 400;