2495. Number of Unique Subjects Taught by Each Teacher
My accepted SQL solution to LeetCode problem 2495, Number of Unique Subjects Taught by Each Teacher, running in 474ms.
- Difficulty: Easy
- SQL
- Runtime 474ms
- Memory 0.0B
- Updated
Read the problem on LeetCode View on GitHub
The problem statement is LeetCode’s and stays on their site. What follows is my accepted solution.
SQL
Accepted on LeetCode — runtime 474ms, memory 0.0B, accepted 2026-01-01.
SELECT teacher_id, COUNT(DISTINCT subject_id) AS cnt
FROM Teacher
GROUP BY teacher_id