educative.io

Educative

Question 1 answer using correlated subquery, as another option

The suggested solution is interesting, but just for those who are interested - another approach with correlated subquery can also be used here:

select Weekend, RevenueInMillions, 
    (select sum(RevenueInMillions) 
     from MovieScreening m2 
     where m2.MovieId = 10 and m2.Weekend <= m1.Weekend) as RunningTotal 
from MovieScreening m1 
where m1.MovieId = 10;

But window functions are definitely a way to go in such tasks.


Course: https://www.educative.io/collection/5352985413550080/6335716377231360
Lesson: https://www.educative.io/collection/page/5352985413550080/6335716377231360/5327494434521088


Course: https://www.educative.io/collection/5352985413550080/6335716377231360
Lesson: https://www.educative.io/collection/page/5352985413550080/6335716377231360/5327494434521088

Hey @Dmitry_Polovinkin!

Your provided query also solves this problem, as there might be multiple methods to solve a problem. Also, thank you for pointing this out. We are working on reviewing this course, and we will soon fix the gaps in this course.

Happy learning!