GROUP BY clause to group records by teacher_id.COUNT(DISTINCT subject_id) function to count the unique subjects taught by each teacher.teacher_id and the count from step 2 as cnt to match the expected output format.For the Pandas approach:
teacher_id using the groupby() function.nunique() function to the subject_id column to count unique subjects.cnt to match the expected output format.
erDiagram
Teacher {
int teacher_id
int subject_id
int dept_id
subject_id PK ""
dept_id PK ""
}