97.8k views
2 votes
SELECT COUNT(a.actor_id) as num_actors FROM Movie m JOIN Actor a ON m.movie_id = a.movie_id GROUP BY m.movie_id HAVING num_actors > 3;

User Yoco
by
7.6k points

1 Answer

1 vote

Final answer:

The SQL query counts actors per movie, joining two tables, and filters results to only include movies with more than three actors.

Step-by-step explanation:

The query in question is written in SQL (Structured Query Language) and is used for retrieving data from a relational database. The purpose of this query is to count the number of actors associated with each movie in a database where the number of actors is greater than three.

The query selects the number of actors for each movie by joining the Movie and Actor tables on the common column movie_id. The COUNT function is used to tally the number of actor entries per movie, and the GROUP BY clause groups the results by movie_id.

Finally, the query filters out the groups with three or fewer actors using the HAVING clause, implying that only movies with more than three actors will be included in the result set.

User Eric Cote
by
7.8k points