https://leetcode.com/problems/number-of-unique-subjects-taught-by-each-teacher
문제에서 요구하는 것은, 각 선생님이 가르치는 과목의 수이다.
선생님을 의미하는 teacher_id 을 group by 로 묶고,
선생님이 가르치는 과목을 의미하는 subject_id 의 유니크한 개수를 계산해주면 된다.
select teacher_id, count(distinct(subject_id)) as cnt
from Teacher
group by teacher_id
< English (feedback by ChatGPT) >
What the problem requires is the number of subject of each teacher.
(What the problem requires is the number of subjects each teacher teaches.)
We group by teacher_id which represent a teacher
(We group by teacher_id, which represents a teacher,)
and count the uniqe number of subject_id which represent a subject teachers teach.
(and count the unique number of subject_ids, which represent the subjects being taught.)
'Coding Interview' 카테고리의 다른 글
| [leetcode] 1795. Rearrange Products Table (0) | 2025.05.10 |
|---|---|
| [leetcode] 1741. Find Total Time Spent by Each Employee (0) | 2025.05.10 |
| [leetcode] 160. Intersection of Two Linked Lists (0) | 2025.05.10 |
| [leetcode] 141. Linked List Cycle (0) | 2025.05.09 |
| [leetcode] 121. Best Time to Buy and Sell Stock (0) | 2025.05.09 |