코린이의 소소한 공부노트

[LeetCode/Easy] 2356. Number of Unique Subjects Taught by Each Teacher 본문

코딩테스트 풀이/SQL

[LeetCode/Easy] 2356. Number of Unique Subjects Taught by Each Teacher

무지맘 2023. 5. 2. 10:39

1. Input

1) Table: Teacher (pk: (subject_id, dept_id))

 

2. Output

1) 각 선생님 별로 가르치는 과목 수를 반환

- 출력 순서는 상관 없다.

- 과목 수를 셀 때 중복은 제외한다.

 

3. Example

 

4. Code

1) 첫 코드(2023/05/02)

select teacher_id, count(distinct subject_id) as cnt
from Teacher
group by teacher_id;