Categories:

Tags:



Problem

Table: ActorDirector

+-------------+---------+
| Column Name | Type    |
+-------------+---------+
| actor_id    | int     |
| director_id | int     |
| timestamp   | int     |
+-------------+---------+
timestamp is the primary key (column with unique values) for this table.

Write a solution to find all the pairs (actor_id, director_id) where the actor has cooperated with the director at least three times.

Return the result table in any order.

Solution

The problem Actors and Directors Who Cooperated At Least Three Times can be solved using keywords GROUP BY and HAVING along with the function COUNT.

Implementation

# Write your MySQL query statement below

SELECT actor_id, director_id
FROM actordirector
GROUP BY actor_id, director_id
HAVING COUNT(timestamp) >= 3;