1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-01-10 18:48:13 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
leetcode-problemset/leetcode-cn/originData/number-of-unique-subjects-taught-by-each-teacher.json
2023-12-09 19:57:46 +08:00

94 lines
9.0 KiB
JSON

{
"data": {
"question": {
"questionId": "2495",
"questionFrontendId": "2356",
"categoryTitle": "Database",
"boundTopicId": 1706030,
"title": "Number of Unique Subjects Taught by Each Teacher",
"titleSlug": "number-of-unique-subjects-taught-by-each-teacher",
"content": "<p>Table: <code>Teacher</code></p>\n\n<pre>\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| teacher_id | int |\n| subject_id | int |\n| dept_id | int |\n+-------------+------+\n(subject_id, dept_id) is the primary key (combinations of columns with unique values) of this table.\nEach row in this table indicates that the teacher with teacher_id teaches the subject subject_id in the department dept_id.\n</pre>\n\n<p>&nbsp;</p>\n\n<p>Write a solution to calculate&nbsp;the number of unique subjects each teacher teaches in the university.</p>\n\n<p>Return the result table in <strong>any order</strong>.</p>\n\n<p>The&nbsp;result format is shown in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \nTeacher table:\n+------------+------------+---------+\n| teacher_id | subject_id | dept_id |\n+------------+------------+---------+\n| 1 | 2 | 3 |\n| 1 | 2 | 4 |\n| 1 | 3 | 3 |\n| 2 | 1 | 1 |\n| 2 | 2 | 1 |\n| 2 | 3 | 1 |\n| 2 | 4 | 1 |\n+------------+------------+---------+\n<strong>Output:</strong> \n+------------+-----+\n| teacher_id | cnt |\n+------------+-----+\n| 1 | 2 |\n| 2 | 4 |\n+------------+-----+\n<strong>Explanation:</strong> \nTeacher 1:\n - They teach subject 2 in departments 3 and 4.\n - They teach subject 3 in department 3.\nTeacher 2:\n - They teach subject 1 in department 1.\n - They teach subject 2 in department 1.\n - They teach subject 3 in department 1.\n - They teach subject 4 in department 1.\n</pre>\n",
"translatedTitle": "每位教师所教授的科目种类的数量",
"translatedContent": "<p>表: <code>Teacher</code></p>\n\n<pre>\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| teacher_id | int |\n| subject_id | int |\n| dept_id | int |\n+-------------+------+\n在 SQL 中,(subject_id, dept_id) 是该表的主键。\n该表中的每一行都表示带有 teacher_id 的教师在系 dept_id 中教授科目 subject_id。\n</pre>\n\n<p>&nbsp;</p>\n\n<p>查询每位老师在大学里教授的科目种类的数量。</p>\n\n<p data-group=\"1-1\">以 <strong>任意顺序</strong> 返回结果表。</p>\n\n<p>查询结果格式示例如下。</p>\n\n<p>&nbsp;</p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong> \nTeacher 表:\n+------------+------------+---------+\n| teacher_id | subject_id | dept_id |\n+------------+------------+---------+\n| 1 | 2 | 3 |\n| 1 | 2 | 4 |\n| 1 | 3 | 3 |\n| 2 | 1 | 1 |\n| 2 | 2 | 1 |\n| 2 | 3 | 1 |\n| 2 | 4 | 1 |\n+------------+------------+---------+\n<strong>输出:</strong> \n+------------+-----+\n| teacher_id | cnt |\n+------------+-----+\n| 1 | 2 |\n| 2 | 4 |\n+------------+-----+\n<strong>解释:</strong> \n教师 1:\n - 他在 3、4 系教科目 2。\n - 他在 3 系教科目 3。\n教师 2:\n - 他在 1 系教科目 1。\n - 他在 1 系教科目 2。\n - 他在 1 系教科目 3。\n - 他在 1 系教科目 4。</pre>\n",
"isPaidOnly": false,
"difficulty": "Easy",
"likes": 19,
"dislikes": 0,
"isLiked": null,
"similarQuestions": "[]",
"contributors": [],
"langToValidPlayground": "{\"cpp\": false, \"java\": false, \"python\": false, \"python3\": false, \"mysql\": false, \"mssql\": false, \"oraclesql\": false, \"c\": false, \"csharp\": false, \"javascript\": false, \"typescript\": false, \"bash\": false, \"php\": false, \"swift\": false, \"kotlin\": false, \"dart\": false, \"golang\": false, \"ruby\": false, \"scala\": false, \"html\": false, \"pythonml\": false, \"rust\": false, \"racket\": false, \"erlang\": false, \"elixir\": false, \"pythondata\": false, \"react\": false, \"vanillajs\": false, \"postgresql\": false}",
"topicTags": [
{
"name": "Database",
"slug": "database",
"translatedName": "数据库",
"__typename": "TopicTagNode"
}
],
"companyTagStats": null,
"codeSnippets": [
{
"lang": "MySQL",
"langSlug": "mysql",
"code": "# Write your MySQL query statement below",
"__typename": "CodeSnippetNode"
},
{
"lang": "MS SQL Server",
"langSlug": "mssql",
"code": "/* Write your T-SQL query statement below */",
"__typename": "CodeSnippetNode"
},
{
"lang": "Oracle",
"langSlug": "oraclesql",
"code": "/* Write your PL/SQL query statement below */",
"__typename": "CodeSnippetNode"
},
{
"lang": "Pandas",
"langSlug": "pythondata",
"code": "import pandas as pd\n\ndef count_unique_subjects(teacher: pd.DataFrame) -> pd.DataFrame:\n ",
"__typename": "CodeSnippetNode"
},
{
"lang": "PostgreSQL",
"langSlug": "postgresql",
"code": "-- Write your PostgreSQL query statement below",
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"16.4K\", \"totalSubmission\": \"19.7K\", \"totalAcceptedRaw\": 16358, \"totalSubmissionRaw\": 19708, \"acRate\": \"83.0%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"headers\":{\"Teacher\":[\"teacher_id\",\"subject_id\",\"dept_id\"]},\"rows\":{\"Teacher\":[[1,2,3],[1,2,4],[1,3,3],[2,1,1],[2,2,1],[2,3,1],[2,4,1]]}}",
"metaData": "{\"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\"}}}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"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')"
],
"enableRunCode": true,
"envInfo": "{\"mysql\":[\"MySQL\",\"<p>\\u7248\\u672c\\uff1a<code>MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"<p>mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\"<p>Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\"<p>Python 3.10 with Pandas 2.0.2 and NumPy 1.25.0<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>PostgreSQL 16<\\/p>\"]}",
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "{\"headers\":{\"Teacher\":[\"teacher_id\",\"subject_id\",\"dept_id\"]},\"rows\":{\"Teacher\":[[1,2,3],[1,2,4],[1,3,3],[2,1,1],[2,2,1],[2,3,1],[2,4,1]]}}",
"__typename": "QuestionNode"
}
}
}