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.)

 

 

+ Recent posts