Number of Unique Subjects Taught by Each Teacher

2pts
Ed Tech

Problem Statement

University administrators need to report on faculty workload. Specifically, they want to know how many different subjects each teacher handles, regardless of how many departments those subjects span.

Write an SQL query to report the number of unique subjects each teacher teaches in the university.

Rules:

  • A teacher may teach the same subject in multiple departments, but it should only be counted once for that teacher.
  • Return the teacher_id and the count of unique subjects (aliased as cnt).
  • Results must be sorted by teacher_id in ascending order.
Tests your understanding of
Basic SQL, Aggregation, COUNT DISTINCT and Grouping

Input Tables

teacher
teacher_id(INTEGER)subject_id(INTEGER)dept_id(INTEGER)
123
124
133
211
221
231
241

Expected Output

teacher_id(INTEGER)cnt(INTEGER)
12
24

Tags

EasyBasic SQLAggregationCOUNT DISTINCTGrouping
5-10 min
88%

Hints