1050. Actors and Directors Who Cooperated At Least Three Times
Problem Statement
Find all the actor and director pairs where the actor cooperated with the director at least three times. Return the result table in any order.
Table Schema
Table: ActorDirector
+-------------+---------+
| actor_id | int |
| director_id | int |
| timestamp | int |
+-------------+---------+
timestamp is the primary key.
Examples
Example 1
Input Table:
ActorDirector table:
+-------------+-------------+-----------+
| actor_id | director_id | timestamp |
+-------------+-------------+-----------+
| 1 | 1 | 0 |
| 1 | 1 | 1 |
| 1 | 1 | 2 |
| 1 | 2 | 3 |
| 1 | 2 | 4 |
| 2 | 1 | 5 |
+-------------+-------------+-----------+
Expected Output:
+-------------+-------------+
| actor_id | director_id |
+-------------+-------------+
| 1 | 1 |
+-------------+-------------+
SQL Solution
SELECT actor_id, director_id
FROM ActorDirector
GROUP BY actor_id, director_id
HAVING COUNT(*) >= 3;
Problem Info
DifficultyEASY
Topics
group-byhaving