본문 바로가기

Algorithm/SQL

(SQL) - LeetCode (easy) 1050. Actors and Directors Who Cooperated At Least Three Times

반응형

https://leetcode.com/problems/actors-and-directors-who-cooperated-at-least-three-times/

 

Actors and Directors Who Cooperated At Least Three Times - LeetCode

Can you solve this real interview question? Actors and Directors Who Cooperated At Least Three Times - Table: ActorDirector +-------------+---------+ | Column Name | Type | +-------------+---------+ | actor_id | int | | director_id | int | | timestamp | in

leetcode.com

group by를 사용해보는 문제였습니다.

📕 풀이방법

📔 풀이과정

actor_id, director_id에 대해 구분되는 group by를 수행한 후 timestamp의 행을 세었을 때 3이상인 row를 select해주면 됩니다.


📕 Code

📔 MySQL, ORACLE

select actor_id, director_id from actordirector
group by actor_id, director_id
having count(timestamp) >= 3;

*더 나은 내용을 위한 지적, 조언은 언제나 환영합니다.