Data-Driven Decision Making in SQL
Bart Baesens
Professor Data Science and Analytics
SELECT *
FROM movies as m
WHERE 5 <
(SELECT COUNT(*)
FROM renting as r
WHERE r.movie_id=m.movie_id);
SELECT COUNT(*)
FROM renting as r
WHERE r.movie_id = 1;
| count |
|-------|
| 8 |
Number of movie rentals larger than 5
SELECT *
FROM movies as m
WHERE 5 <
(SELECT COUNT(*)
FROM renting as r
WHERE r.movie_id = m.movie_id);
| movie_id | title | genre | runtime | year_of_release | renting_price |
|----------|-----------------------|--------|---------|-----------------|---------------|
| 1 | One Night at McCool's | Comedy | 93 | 2001 | 2.09 |
| 2 | Swordfish | Drama | 99 | 2001 | 2.19 |
Select movies with less than 5 movie rentals.
SELECT *
FROM movies as m
WHERE 5 >
(SELECT COUNT(*)
FROM renting as r
WHERE r.movie_id = m.movie_id);
| movie_id | title | genre | runtime | year_of_release | renting_price |
|----------|-----------------|--------------------|---------|-----------------|---------------|
| 17 | The Human Stain | Mystery & Suspense | 106 | 2003 | 1.99 |
| 20 | Love Actually | Comedy | 135 | 2003 | 2.29 |
Data-Driven Decision Making in SQL