Given a table ActorDirector that contains information about actors and directors who have worked together on movies.
Write a SQL solution to find all pairs (actor_id, director_id) where the actor has cooperated with the director at least three times.
Return the result table in any order.
Table Schema
| Column Name | Type | Description |
|---|---|---|
actor_id
|
int | ID of the actor |
director_id
|
int | ID of the director |
timestamp
PK
|
int | Timestamp when they worked together |
Input & Output
| actor_id | director_id | timestamp |
|---|---|---|
| 1 | 1 | 0 |
| 1 | 1 | 1 |
| 1 | 1 | 2 |
| 1 | 2 | 3 |
| 1 | 2 | 4 |
| 2 | 1 | 5 |
| 2 | 1 | 6 |
| actor_id | director_id |
|---|---|
| 1 | 1 |
Actor 1 worked with Director 1 three times (timestamps 0, 1, 2), which meets the requirement of at least 3 collaborations. Actor 1 worked with Director 2 only twice (timestamps 3, 4), and Actor 2 worked with Director 1 only twice (timestamps 5, 6), so these pairs don't qualify.
| actor_id | director_id | timestamp |
|---|---|---|
| 1 | 1 | 0 |
| 1 | 2 | 1 |
| 2 | 1 | 2 |
| 2 | 2 | 3 |
| actor_id | director_id |
|---|
No actor-director pair has worked together 3 or more times. Each pair has collaborated only once, so no pairs meet the minimum requirement of 3 collaborations.
| actor_id | director_id | timestamp |
|---|---|---|
| 1 | 1 | 0 |
| 1 | 1 | 1 |
| 1 | 1 | 2 |
| 2 | 1 | 3 |
| 2 | 1 | 4 |
| 2 | 1 | 5 |
| actor_id | director_id |
|---|---|
| 1 | 1 |
| 2 | 1 |
Both Actor 1 and Actor 2 have worked with Director 1 exactly 3 times each, so both pairs qualify for the result.
Constraints
-
1 ≤ actor_id, director_id ≤ 1000 -
0 ≤ timestamp ≤ 10^9 -
timestampvalues are unique