Join ML Engineer Interview MasterClass (April Cohort) led by FAANG Data Scientists | Just 6 seats remaining...
ML Engineer MasterClass (April) | 6 seats left
By the end of this lesson, you will:
Your manager at Netflix, Alex, is analyzing mid-era releases and wants to focus on shows released between 2015 and 2020.
Alex asks:
Can you retrieve all Netflix series that were released between 2015 and 2020?
Your task is to query the netflix_series table and provide the requested data.
| series_id | title | genre | release_year | seasons | rating | total_views_millions |
|---|---|---|---|---|---|---|
| 1 | Stranger Things | Sci-Fi | 2016 | 4 | 8.7 | 140 |
| 2 | Squid Game | Thriller | 2021 | 1 | 8 | 200 |
| 3 | The Witcher | Fantasy | 2019 | 3 | 7.9 | 90 |
| 4 | Money Heist | Crime | 2017 | 5 | 8.2 | 180 |
| 5 | Dark | Sci-Fi | 2017 | 3 | 8.8 | 85 |
The BETWEEN operator filters results within a specified range, including both the lower and upper values.
SELECT column1, column2
FROM table_name
WHERE column_name BETWEEN value1 AND value2;BETWEEN value1 AND value2 includes both value1 and value2 in the result.WHERE column_name >= value1 AND column_name <= value2;Instead of writing:
SELECT title, release_year
FROM netflix_series
WHERE release_year >= 2015 AND release_year <= 2020;You can write:
SELECT title, release_year
FROM netflix_series
WHERE release_year BETWEEN 2015 AND 2020;| title | release_year |
|---|---|
| Narcos | 2015 |
| Stranger Things | 2016 |
| The Crown | 2016 |
| Money Heist | 2017 |
| Dark | 2017 |
| The Witcher | 2019 |
| Bridgerton | 2020 |
What’s Happening?
BETWEEN 2015 AND 2020 filters results to only include release years from 2015 to 2020.>= and <= would be longer and harder to read.You can also apply BETWEEN to numeric values like ratings.
SELECT title, rating
FROM netflix_series
WHERE rating BETWEEN 8.0 AND 9.0;| title | rating |
|---|---|
| “Stranger Things” | 8.7 |
| “Squid Game” | 8 |
| “Money Heist” | 8.2 |
| “Dark” | 8.8 |
| “Narcos” | 8.8 |
| “The Crown” | 8.6 |
| “Black Mirror” | 8.8 |
What’s Happening?
BETWEEN 8.0 AND 9.0 filters results to only include shows with ratings between 8.0 and 9.0.Alex wants a report showing all series released between 2015 and 2020, sorted by release_year in ascending order, then title in ascending order.
Filter condition:
release_year must be between 2015 and 2020.release_year in ascending order, then title in ascending order.| title | release_year |
|---|---|
| Narcos | 2015 |
| Stranger Things | 2016 |
| The Crown | 2016 |
| Money Heist | 2017 |
| Dark | 2017 |
| The Witcher | 2019 |
| Bridgerton | 2020 |
Write an SQL query to return the requested data.
Alex wants to focus on highly-rated Netflix shows that have ratings between 8.0 and 9.0.
Filter condition:
rating must be between 8.0 and 9.0.rating in ascending order, then title in ascending order.| title | rating |
|---|---|
| “Squid Game” | 8 |
| “Money Heist” | 8.2 |
| “The Crown” | 8.6 |
| “Stranger Things” | 8.7 |
| “Black Mirror” | 8.8 |
| “Dark” | 8.8 |
| “Narcos” | 8.8 |
Write an SQL query to return the requested data.