There are currently no frequently asked questions associated with this exercise – that’s where you come in! You can contribute to this section by offering your own questions, answers, or clarifications on this exercise. Ask or answer a question by clicking reply () below.
If you’ve had an “aha” moment about the concepts, formatting, syntax, or anything else with this exercise, consider sharing those insights! Teaching others and answering their questions is one of the best ways to learn and stay sharp.
Join the Discussion. Help a fellow learner on their journey.
Ask or answer a question about this exercise by clicking reply () below!
Agree with a comment or answer? Like () to up-vote the contribution!
My instructions say to rename the results. When trying to add the AS statement it would not accept my answer. When I clicked the hint it did not have the AS statements. So why is it telling me to rename anything? Did anyone else have this issue or did I just massively over think this test?
I thought the same thing. I had renamed them and it was failing me. Then I noticed that the order of the MIN, MAX makes a difference. If you use MIN first it fails but MAX first succeeds, named or not.
Ok, problem is solved. Just swapped function MAX() and MIN().
Correct code is:
SELECT MAX(watch_duration_in_minutes) AS ‘max’, MIN(watch_duration_in_minutes) AS ‘min’
FROM watch_history;
After run the collect query, the result appear, max and min.
Are those results different ‘user_id’(or ‘id’)?
When I tried to put ‘SELECT user_id …,’ in the first line, the result was just ‘user_id’ is added on the left. It looks like same user_id happen to have max and min at the same time?
I guess that each column shows independent results.
Hello to every/anyone, I have a questions regarding column referencing, specifically from question 6 of this exercise
I had tried to use the following syntax for my answer, which would be correct if i simply didn’t use the column references, but is showing up as wrong when I replace the columns in the select statement with numbers. I tried tinkering with it and it boiled down to the SUM function in the SELECT statement - apparently I can reference the user_id column and I’ll get a resulting query, but once i reference the SUM column, the query fails (even without the alias). Anyone know why?
SELECT user_id, SUM(watch_duration_in_minutes) AS ‘total_minutes’
FROM watch_history
GROUP BY 1
HAVING 2 > 400;
Any help would be appreciated!
EDIT: looks like you can’t reference a column as a number if you’re using operators because SQL won’t see “2” as a reference. Can someone confirm this?
SOLVED: confirmed in next section (How to Hack Hacker News) - HAVING doesn’t support aliases so you’d need to spell out the entire aggregate function column.