title
------------------------
ACADEMY DINOSAUR
ARABIA DOGMA
Solution
postgres
WITH film_casts_cnt AS (
SELECT
film_id,
COUNT(*) AS actors_cnt
FROM film_actor
GROUP BY film_id
HAVING COUNT(*)>=10
)
SELECT title
FROM film
WHERE film_id IN (
SELECT film_id
FROM film_casts_cnt
)
Explanation
This query is selecting the titles of all films that have 10 or more actors in their cast.
The first part of the query creates a temporary table called "film_casts_cnt" which contains the count of actors in each film. It does this by grouping the "film_actor" table by film_id and counting the number of rows in each group. It then filters this table to only include films with 10 or more actors.
The second part of the query selects the titles of all films where the film_id is in the "film_casts_cnt" table. This effectively joins the two tables on the film_id column and returns the title for each matching row.
Copied
Last Submission
postgres
No submission yet for this engine. Run and submit your query to save it here.
Copied
Expected results
Submit a query to compare against expected output.