Skip to content
Data-Driven Decision Making in SQL - For real
Data-Driven Decision Making in SQL
Here you can access every table used in the course. To access each table, you will need to specify the movies schema in your queries (e.g., movies.movies for the movies table, and movies.customers for the customers table).
Take Notes
Add notes about the concepts you've learned and SQL cells with queries you want to keep.
Tables in the course
MOVIES: is the main schema and have 5 different tables
- Customers
- Movies
- Renting: All movies rentals
- Actors: Actors in the movies
- Actsin: MOVIES <> ACTORS -> Which actors appeared in each movie
Explore databases
DataFrameas
df
variable
[2]
-- Add your own queries here
SELECT *
FROM movies.customers
LIMIT 5DataFrameas
df1
variable
-- Add your own queries here
SELECT *
FROM movies.movies
LIMIT 5DataFrameas
df2
variable
-- Add your own queries here
SELECT *
FROM movies.renting
LIMIT 5DataFrameas
actors
variable
-- Add your own queries here
SELECT *
FROM movies.actors
LIMIT 5Money Spent per customers with sub-queries
- Renting price for rental and its customer id
- Customer_ID
- Renting_Price
- Sum of all renting per customer
- Customer_ID
- sum(Renting_Price)
DataFrameas
df3
variable
SELECT rm.customer_id, SUM(rm.renting_price)
FROM (SELECT r.customer_id,
m.renting_price
FROM movies.renting AS r
LEFT JOIN movies.movies AS m
ON r.movie_id=m.movie_id) AS rm
GROUP BY rm.customer_id
;
DataFrameas
df4
variable
SELECT extract(year from date_trunc('decade', date_of_birth))
from movies.customersNested Subquery
- Who are the actors in the movie Ray?
- Filter Movie with title Ray
- Get it's
moview_id
- Using another table Actsin do the match MOVIES <> ACTOR
- Get
actor_idfrom the ones that participated in the movie
- Get the name given actor_id
DataFrameas
df5
variable
SELECT c.name
FROM movies.actors as c
WHERE actor_id IN
(SELECT actor_id
FROM movies.actsin
WHERE movie_id =
-- Filter Movie with title Ray
(SELECT movie_id
FROM movies.movies
WHERE title='Ray'));Correlated Queries
Definition= The Subquery is evaluated multiple times
-
In other words:
-
Condition in the WHERE clause of the inner query.
-
References some column of a table in the outer query.
Exists
- Same as
INbut for correlated queries