Number of Unique Subjects Taught by Each Teacher
<p>Table: <code>Teacher</code></p>

<pre>
+-------------+------+
| Column Name | Type |
+-------------+------+
| teacher_id  | int  |
| subject_id  | int  |
| dept_id     | int  |
+-------------+------+
(subject_id, dept_id) is the primary key (combinations of columns with unique values) of this table.
Each row in this table indicates that the teacher with teacher_id teaches the subject subject_id in the department dept_id.
</pre>

<p>&nbsp;</p>

<p>Write a solution to calculate&nbsp;the number of unique subjects each teacher teaches in the university.</p>

<p>Return the result table in <strong>any order</strong>.</p>

<p>The&nbsp;result format is shown in the following example.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<pre>
<strong>Input:</strong> 
Teacher table:
+------------+------------+---------+
| teacher_id | subject_id | dept_id |
+------------+------------+---------+
| 1          | 2          | 3       |
| 1          | 2          | 4       |
| 1          | 3          | 3       |
| 2          | 1          | 1       |
| 2          | 2          | 1       |
| 2          | 3          | 1       |
| 2          | 4          | 1       |
+------------+------------+---------+
<strong>Output:</strong>  
+------------+-----+
| teacher_id | cnt |
+------------+-----+
| 1          | 2   |
| 2          | 4   |
+------------+-----+
<strong>Explanation:</strong> 
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.
</pre>

[]
['Create table If Not Exists Teacher (teacher_id int, subject_id int, dept_id int)', 'Truncate table Teacher', "insert into Teacher (teacher_id, subject_id, dept_id) values ('1', '2', '3')", "insert into Teacher (teacher_id, subject_id, dept_id) values ('1', '2', '4')", "insert into Teacher (teacher_id, subject_id, dept_id) values ('1', '3', '3')", "insert into Teacher (teacher_id, subject_id, dept_id) values ('2', '1', '1')", "insert into Teacher (teacher_id, subject_id, dept_id) values ('2', '2', '1')", "insert into Teacher (teacher_id, subject_id, dept_id) values ('2', '3', '1')", "insert into Teacher (teacher_id, subject_id, dept_id) values ('2', '4', '1')"]
[{"value": "mysql", "text": "MySQL", "defaultCode": "# Write your MySQL query statement below\n"}, {"value": "mssql", "text": "MS SQL Server", "defaultCode": "/* Write your T-SQL query statement below */\n"}, {"value": "oraclesql", "text": "Oracle", "defaultCode": "/* Write your PL/SQL query statement below */\n"}, {"value": "pythondata", "text": "Pandas", "defaultCode": "import pandas as pd\n\ndef count_unique_subjects(teacher: pd.DataFrame) -> pd.DataFrame:\n    "}, {"value": "postgresql", "text": "PostgreSQL", "defaultCode": "-- Write your PostgreSQL query statement below\n"}]
{"mysql": ["Create table If Not Exists Teacher (teacher_id int, subject_id int, dept_id int)"], "mssql": ["Create table Teacher (teacher_id int, subject_id int, dept_id int)"], "oraclesql": ["Create table Teacher (teacher_id int, subject_id int, dept_id int)"], "database": true, "name": "count_unique_subjects", "pythondata": ["Teacher = pd.DataFrame([], columns=['teacher_id', 'subject_id', 'dept_id']).astype({'teacher_id':'Int64', 'subject_id':'Int64', 'dept_id':'Int64'})"], "postgresql": ["Create table If Not Exists Teacher (teacher_id int, subject_id int, dept_id int)"], "database_schema": {"Teacher": {"teacher_id": "INT", "subject_id": "INT", "dept_id": "INT"}}}
{"mysql": ["MySQL", "<p><code>MySQL 8.0</code>.</p>"], "mssql": ["MS SQL Server", "<p><code>mssql server 2019</code>.</p>"], "oraclesql": ["Oracle", "<p><code>Oracle Sql 11.2</code>.</p>"], "pythondata": ["Pandas", "<p>Python 3.10 with Pandas 2.2.2 and NumPy 1.26.4</p>"], "postgresql": ["PostgreSQL", "<p>PostgreSQL 16</p>"]}
['Database']