๐ข ๋ณธ ํฌ์คํ ์ ํ์ฉ๋๋ ๊ธฐ๋ณธ ๋ฌธ์ ๋ฐ ์๋ฃ ์ถ์ฒ๋
๋ฆฌํธ์ฝ๋ Problems, https://leetcode.com/problemset/all/์์ ๋ฐํ๋๋ค.
โ๋ฌธ์
https://leetcode.com/problems/actors-and-directors-who-cooperated-at-least-three-times/description/
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
Table : ActorDirector
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.
The result format is in the following example.
โ ํ์ด
๋ฌธ์ ์๊ตฌ์ฌํญ
๋ฐฐ์ฐ์ ๊ฐ๋ ์ด ์ต์ 3๋ฒ ์ด์ ํ์ ํ ํ์ด๋ฅผ ์ฐพ๋ ๊ฒ์ด ๋ฌธ์ ์ด๋ค.
์ง์ ์ฐพ๋ ์ฌ์ด ๋ฐฉ๋ฒ์ผ๋ก group by ๋ฅผ ์ ์ฉํ๋ค.
actor_id์ director_id์ ๋ํด group์ ์ ์ฉํ๋ฉด <์์¹> ์ ๊ฐ์ด ์ต์ข ์ ์ผ๋ก ํ์ด ํ์๋ฅผ countํ ์ ์๋ค.
์ด๋ฒ ๋ฌธ์ ์์๋ ํ์ด ํ์๊ฐ ์ต์ 3ํ ์ด์์ด ์กฐ๊ฑด์ผ๋ก ์ฃผ์ด์ก์ผ๋ฏ๋ก ์ง๊ณ์ ๋ํ ์กฐ๊ฑด์ having์ ์ ์ ์ฉํด์ ์๋ ์ฟผ๋ฆฌ๋ก ๋ต์์ ์ถ๋ ฅํ๋ค.
SELECT actor_id, director_id
FROM ActorDirector
GROUP BY 1, 2
HAVING COUNT(*) >= 3;
1. ์์
SELECT actor_id, director_id, COUNT(*)
FROM ActorDirector
GROUP BY 1, 2;
'Growth ๐ณ > Practice ๐ป' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Leet code] 1141. User Activity for the Past 30 Days IEasy474634 (0) | 2023.09.13 |
---|---|
[Leet code] 610. Triangle Judgement (0) | 2023.09.13 |
[Leet code] 619. Biggest Single Number (0) | 2023.09.02 |
[Leet code] 1173. Immediate Food Delivery I (0) | 2023.08.03 |
[Leet code] 1164. Product Price at a Given Date (0) | 2023.07.17 |