#5 Subqueries and CTEs
#5.1 Introduction
-- List movies with a (rating|revenue) higher than the average (rating|revenue) of all movies.
-- List movies with a rating higher than the average rating of movies in their genre.
-- Find the directors with a career revenue higher than the average revenue of all directors.
-- Find the movies with a rating higher than the average rating of movies released in the same year.
-- Make a super slow query and optimize it as much as we can with what we know so far.#5.1 Independent Subqueries
-- List movies with a (rating|revenue) higher
-- than the average (rating|revenue) of all movies.
SELECT title, rating, revenue
FROM movies
WHERE
rating > (SELECT avg(rating) FROM movies) AND
revenue > (SELECT avg(revenue) FROM movies)#5.2 CTEs
#5.3 Correlated Subqueries
#5.4 Correlated CTEs
#5.5 Subquery Practice
#5.6 Final Practice
Last updated