The Actors and Directors Who Cooperated At Least Three Times coding problem is a straightforward relational data task. You have a table recording every time an actor and a director worked together on a project. You need to identify pairs of (Actor, Director) who have collaborated at least three times.
Companies like Microsoft and Amazon use this Actors and Directors interview question to verify basic SQL fluency. It assesses your ability to use multi-column grouping and filtering on aggregated data, which are fundamental skills for any data-focused role.
The pattern here is the Group By and Having interview pattern. Unlike a simple group by on one column, you group by a pair of columns to find the intersection of two entities and then use the HAVING clause to filter the result based on the count.
Consider the following ActorDirector table:
When we group by (actor_id, director_id):
WHERE clause for the count. Remember: WHERE filters rows before grouping, while HAVING filters after grouping.SELECT list that are not in the GROUP BY clause, which causes errors in most SQL environments.Always remember the SQL execution order: FROM WHERE GROUP BY HAVING SELECT. Knowing this prevents you from trying to filter aggregates in the wrong place.