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, wants to analyze the most popular Crime and Sci-Fi series to identify trends among viewers.
Alex asks:
Can you retrieve all Netflix series that belong to either the ‘Crime’ or ‘Sci-Fi’ genres?
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 |
INThe IN operator allows you to filter data based on multiple values. Instead of using multiple OR conditions, IN makes queries cleaner and more efficient.
SELECT column1, column2
FROM table_name
WHERE column_name IN (value1, value2, ...);column_name matches any value listed inside IN().OR conditions.IN for Genre FilteringInstead of writing:
SELECT title, genre
FROM netflix_series
WHERE genre = 'Crime' OR genre = 'Sci-Fi';You can write:
SELECT title, genre
FROM netflix_series
WHERE genre IN ('Crime', 'Sci-Fi');| title | genre |
|---|---|
| Stranger Things | Sci-Fi |
| Dark | Sci-Fi |
| Black Mirror | Sci-Fi |
| Money Heist | Crime |
| Narcos | Crime |
| Breaking Bad | Crime |
What’s Happening?
IN ('Crime', 'Sci-Fi') filters only shows within these genres.OR conditions.IN with Numeric ValuesThe IN clause also works for numeric comparisons.
SELECT title, release_year
FROM netflix_series
WHERE release_year IN (2015, 2017, 2020);| title | release_year |
|---|---|
| Narcos | 2015 |
| Money Heist | 2017 |
| Dark | 2017 |
| Bridgerton | 2020 |
What’s Happening?
IN, we would have to write:sqlCopyEditWHERE release_year = 2015 OR release_year = 2017 OR release_year = 2020;Alex wants to analyze popular genres. Retrieve all Netflix series that belong to either the “Crime” or “Sci-Fi” genres, sorted alphabetically by title.
Filter condition:
genre must be ‘Crime’ or ‘Sci-Fi’.title in ascending order.| title | genre |
|---|---|
| Black Mirror | Sci-Fi |
| Breaking Bad | Crime |
| Dark | Sci-Fi |
| Money Heist | Crime |
| Narcos | Crime |
| Stranger Things | Sci-Fi |
Write an SQL query to return the requested data.
Alex wants to generate a report showing all series released in 2016, 2017, or 2021, sorted by release_year in ascending order, then title in ascending order.
Filter condition:
release_year must be 2016, 2017, or 2021.release_year in ascending order, then title in ascending order.| title | release_year |
|---|---|
| “Stranger Things” | 2016 |
| “The Crown” | 2016 |
| “Dark” | 2017 |
| “Money Heist” | 2017 |
| “Squid Game” | 2021 |
Write an SQL query to return the requested data.