
문제를 이해하고 있다면 바로 풀이를 보면 됨
전체 코드로 바로 넘어가도 됨
마음대로 번역해서 오역이 있을 수 있음
Table: ActorDirector
| Column Name | Type |
|---|---|
| actor_id | int |
| director_id | int |
| timestamp | int |
timestamp는 이 테이블의 기본 키이다.
배우가 감독과 최소 세 번 이상 협업한 모든 (actor_id, director_id) 쌍을 찾는 방법을 작성해라.
Input:
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 |
| 2 | 1 | 6 |
Output:
| actor_id | director_id |
|---|---|
| 1 | 1 |
Explanation: 오직 (1, 1) 쌍만 정확히 세 번 협업했다.
-- Write your PostgreSQL query statement below
select actor_id, director_id
from ActorDirector
group by actor_id, director_id
having count(timestamp) >= 3