Study - Problems(IT)/LeetCode - SQL

2356.Number of Unique Subjects Taught by Each Teacher

Dev.D 2024. 11. 20. 07:56

*Problem 

Write a solution to calculate the number of unique subjects each teacher teaches in the university.

Return the result table in any order.

 

*Explanation

Teacher 1:
  - They teach subject 2 in departments 3 and 4.
  - They teach subject 3 in department 3.
Teacher 2:
  - They teach subject 1 in department 1.
  - They teach subject 2 in department 1.
  - They teach subject 3 in department 1.
  - They teach subject 4 in department 1.

 

*Solution(Success)

# Write your MySQL query statement below
select teacher_id, 
       count(distinct(subject_id)) cnt
  from Teacher
  group by teacher_id

 

'Study - Problems(IT) > LeetCode - SQL' 카테고리의 다른 글

1070. Product Sales Analysis 3  (0) 2024.11.22
1141.User Activity for the Past 30 Days I  (1) 2024.11.21
550. Game Play Analysis IV  (0) 2024.11.19
1174.Immediate Food Delivery2  (2) 2024.11.17
1193.Monthly Transactions  (0) 2024.11.16