FAQ: Interview Prep Problems - Code Challenge 9

This community-built FAQ covers the “Code Challenge 9” exercise from the lesson “Interview Prep Problems”.

Paths and Courses
This exercise can be found in the following Codecademy content:

Analyze Data with SQL

FAQs on the exercise Code Challenge 9

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 (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 (reply) below!
You can also find further discussion and get answers to your questions over in Language Help.

Agree with a comment or answer? Like (like) to up-vote the contribution!

Need broader help or resources? Head to Language Help and Tips and Resources. If you are wanting feedback or inspiration for a project, check out Projects.

Looking for motivation to keep learning? Join our wider discussions in Community

Learn more about how to use this guide.

Found a bug? Report it online, or post in Bug Reporting

Have a question about your account or billing? Reach out to our customer support team!

None of the above? Find out where to ask other questions here!

This isn’t so much a question… but isn’t the resulting column (running_total_gross) just ‘to_date_gross’? That’s what the gross to date IS.

What an odd challenge…

1 Like

I’m struggling with how to phrase this, but I think this exercise is an error. That is, I think it wasn’t implemented properly by whoever implemented these exercises.

Using a window function with PARTITION BY , get the total change in gross for each movie up to the current week and display it next to the current week column along with the title , week , and gross columns.

So, specifically, the directions are to get the ‘change in gross’ and display it. But the answer to the challenge is as follows:
SELECT title,week,gross, SUM(gross) OVER ( PARTITION BY title ORDER BY week ) AS 'running_total_gross' FROM box_office;

The tip-off here that this is an implementation error is that the directions ask for the change in gross, and yet in the passing code example they use ‘running_total_gross’ as a column name. Additionally, one wouldn’t expect to use the SUM aggregate when trying to calculate the change from week to week. Granted I’m just learning SQL, but upon reading the directions my first instinct was to use LAG. Someone should probably review this one.

3 Likes

I agree with both of the above and reported this as a bug. The assignment and accepted answer don’t match, and the accepted answer is unnecessary as there is already a column for it.

Technically, the assignment should probably be reworded: “total change in gross” would actually just be that week’s gross which is also its own column. I think the intent behind the assignment is to find “change in weekly gross”

2 Likes

Completely agree with above, this question looks like a mistake. The answer they want is the same as the to_date_gross column, but the question suggests we should provide the change in gross each week using LAG function.

2 Likes