mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-01-10 18:48:13 +08:00
109 lines
16 KiB
JSON
109 lines
16 KiB
JSON
{
|
||
"data": {
|
||
"question": {
|
||
"questionId": "1415",
|
||
"questionFrontendId": "1280",
|
||
"categoryTitle": "Database",
|
||
"boundTopicId": 51351,
|
||
"title": "Students and Examinations",
|
||
"titleSlug": "students-and-examinations",
|
||
"content": "<p>Table: <code>Students</code></p>\n\n<pre>\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| student_id | int |\n| student_name | varchar |\n+---------------+---------+\nstudent_id is the primary key (column with unique values) for this table.\nEach row of this table contains the ID and the name of one student in the school.\n</pre>\n\n<p> </p>\n\n<p>Table: <code>Subjects</code></p>\n\n<pre>\n+--------------+---------+\n| Column Name | Type |\n+--------------+---------+\n| subject_name | varchar |\n+--------------+---------+\nsubject_name is the primary key (column with unique values) for this table.\nEach row of this table contains the name of one subject in the school.\n</pre>\n\n<p> </p>\n\n<p>Table: <code>Examinations</code></p>\n\n<pre>\n+--------------+---------+\n| Column Name | Type |\n+--------------+---------+\n| student_id | int |\n| subject_name | varchar |\n+--------------+---------+\nThere is no primary key (column with unique values) for this table. It may contain duplicates.\nEach student from the Students table takes every course from the Subjects table.\nEach row of this table indicates that a student with ID student_id attended the exam of subject_name.\n</pre>\n\n<p> </p>\n\n<p>Write a solution to find the number of times each student attended each exam.</p>\n\n<p>Return the result table ordered by <code>student_id</code> and <code>subject_name</code>.</p>\n\n<p>The result format is in the following example.</p>\n\n<p> </p>\n<p><strong class=\"example\">Example 1:</strong></p>\n\n<pre>\n<strong>Input:</strong> \nStudents table:\n+------------+--------------+\n| student_id | student_name |\n+------------+--------------+\n| 1 | Alice |\n| 2 | Bob |\n| 13 | John |\n| 6 | Alex |\n+------------+--------------+\nSubjects table:\n+--------------+\n| subject_name |\n+--------------+\n| Math |\n| Physics |\n| Programming |\n+--------------+\nExaminations table:\n+------------+--------------+\n| student_id | subject_name |\n+------------+--------------+\n| 1 | Math |\n| 1 | Physics |\n| 1 | Programming |\n| 2 | Programming |\n| 1 | Physics |\n| 1 | Math |\n| 13 | Math |\n| 13 | Programming |\n| 13 | Physics |\n| 2 | Math |\n| 1 | Math |\n+------------+--------------+\n<strong>Output:</strong> \n+------------+--------------+--------------+----------------+\n| student_id | student_name | subject_name | attended_exams |\n+------------+--------------+--------------+----------------+\n| 1 | Alice | Math | 3 |\n| 1 | Alice | Physics | 2 |\n| 1 | Alice | Programming | 1 |\n| 2 | Bob | Math | 1 |\n| 2 | Bob | Physics | 0 |\n| 2 | Bob | Programming | 1 |\n| 6 | Alex | Math | 0 |\n| 6 | Alex | Physics | 0 |\n| 6 | Alex | Programming | 0 |\n| 13 | John | Math | 1 |\n| 13 | John | Physics | 1 |\n| 13 | John | Programming | 1 |\n+------------+--------------+--------------+----------------+\n<strong>Explanation:</strong> \nThe result table should contain all students and all subjects.\nAlice attended the Math exam 3 times, the Physics exam 2 times, and the Programming exam 1 time.\nBob attended the Math exam 1 time, the Programming exam 1 time, and did not attend the Physics exam.\nAlex did not attend any exams.\nJohn attended the Math exam 1 time, the Physics exam 1 time, and the Programming exam 1 time.\n</pre>\n",
|
||
"translatedTitle": "学生们参加各科测试的次数",
|
||
"translatedContent": "<p>学生表: <code>Students</code></p>\n\n<pre>\n+---------------+---------+\n| Column Name | Type |\n+---------------+---------+\n| student_id | int |\n| student_name | varchar |\n+---------------+---------+\n在 SQL 中,主键为 student_id(学生ID)。\n该表内的每一行都记录有学校一名学生的信息。\n</pre>\n\n<p> </p>\n\n<p>科目表: <code>Subjects</code></p>\n\n<pre>\n+--------------+---------+\n| Column Name | Type |\n+--------------+---------+\n| subject_name | varchar |\n+--------------+---------+\n在 SQL 中,主键为 subject_name(科目名称)。\n每一行记录学校的一门科目名称。\n</pre>\n\n<p> </p>\n\n<p>考试表: <code>Examinations</code></p>\n\n<pre>\n+--------------+---------+\n| Column Name | Type |\n+--------------+---------+\n| student_id | int |\n| subject_name | varchar |\n+--------------+---------+\n这个表可能包含重复数据(换句话说,在 SQL 中,这个表没有主键)。\n学生表里的一个学生修读科目表里的每一门科目。\n这张考试表的每一行记录就表示学生表里的某个学生参加了一次科目表里某门科目的测试。\n</pre>\n\n<p> </p>\n\n<p>查询出每个学生参加每一门科目测试的次数,结果按 <code>student_id</code> 和 <code>subject_name</code> 排序。</p>\n\n<p>查询结构格式如下所示。</p>\n\n<p> </p>\n\n<p><strong>示例 1:</strong></p>\n\n<pre>\n<strong>输入:</strong>\nStudents table:\n+------------+--------------+\n| student_id | student_name |\n+------------+--------------+\n| 1 | Alice |\n| 2 | Bob |\n| 13 | John |\n| 6 | Alex |\n+------------+--------------+\nSubjects table:\n+--------------+\n| subject_name |\n+--------------+\n| Math |\n| Physics |\n| Programming |\n+--------------+\nExaminations table:\n+------------+--------------+\n| student_id | subject_name |\n+------------+--------------+\n| 1 | Math |\n| 1 | Physics |\n| 1 | Programming |\n| 2 | Programming |\n| 1 | Physics |\n| 1 | Math |\n| 13 | Math |\n| 13 | Programming |\n| 13 | Physics |\n| 2 | Math |\n| 1 | Math |\n+------------+--------------+\n<strong>输出:</strong>\n+------------+--------------+--------------+----------------+\n| student_id | student_name | subject_name | attended_exams |\n+------------+--------------+--------------+----------------+\n| 1 | Alice | Math | 3 |\n| 1 | Alice | Physics | 2 |\n| 1 | Alice | Programming | 1 |\n| 2 | Bob | Math | 1 |\n| 2 | Bob | Physics | 0 |\n| 2 | Bob | Programming | 1 |\n| 6 | Alex | Math | 0 |\n| 6 | Alex | Physics | 0 |\n| 6 | Alex | Programming | 0 |\n| 13 | John | Math | 1 |\n| 13 | John | Physics | 1 |\n| 13 | John | Programming | 1 |\n+------------+--------------+--------------+----------------+\n<strong>解释:</strong>\n结果表需包含所有学生和所有科目(即便测试次数为0):\nAlice 参加了 3 次数学测试, 2 次物理测试,以及 1 次编程测试;\nBob 参加了 1 次数学测试, 1 次编程测试,没有参加物理测试;\nAlex 啥测试都没参加;\nJohn 参加了数学、物理、编程测试各 1 次。\n</pre>\n",
|
||
"isPaidOnly": false,
|
||
"difficulty": "Easy",
|
||
"likes": 220,
|
||
"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 students_and_examinations(students: pd.DataFrame, subjects: pd.DataFrame, examinations: pd.DataFrame) -> pd.DataFrame:\n ",
|
||
"__typename": "CodeSnippetNode"
|
||
},
|
||
{
|
||
"lang": "PostgreSQL",
|
||
"langSlug": "postgresql",
|
||
"code": "-- Write your PostgreSQL query statement below",
|
||
"__typename": "CodeSnippetNode"
|
||
}
|
||
],
|
||
"stats": "{\"totalAccepted\": \"36K\", \"totalSubmission\": \"72.6K\", \"totalAcceptedRaw\": 35962, \"totalSubmissionRaw\": 72633, \"acRate\": \"49.5%\"}",
|
||
"hints": [],
|
||
"solution": null,
|
||
"status": null,
|
||
"sampleTestCase": "{\"headers\":{\"Students\":[\"student_id\",\"student_name\"],\"Subjects\":[\"subject_name\"],\"Examinations\":[\"student_id\",\"subject_name\"]},\"rows\":{\"Students\":[[1,\"Alice\"],[2,\"Bob\"],[13,\"John\"],[6,\"Alex\"]],\"Subjects\":[[\"Math\"],[\"Physics\"],[\"Programming\"]],\"Examinations\":[[1,\"Math\"],[1,\"Physics\"],[1,\"Programming\"],[2,\"Programming\"],[1,\"Physics\"],[1,\"Math\"],[13,\"Math\"],[13,\"Programming\"],[13,\"Physics\"],[2,\"Math\"],[1,\"Math\"]]}}",
|
||
"metaData": "{\"mysql\":[\"Create table If Not Exists Students (student_id int, student_name varchar(20))\",\"Create table If Not Exists Subjects (subject_name varchar(20))\",\"Create table If Not Exists Examinations (student_id int, subject_name varchar(20))\"],\"mssql\":[\"Create table Students (student_id int, student_name varchar(20))\",\"Create table Subjects (subject_name varchar(20))\",\"Create table Examinations (student_id int, subject_name varchar(20))\"],\"oraclesql\":[\"Create table Students (student_id int, student_name varchar(20))\\n\",\"Create table Subjects (subject_name varchar(20))\\n\",\"Create table Examinations (student_id int, subject_name varchar(20))\"],\"database\":true,\"name\":\"students_and_examinations\",\"pythondata\":[\"Students = pd.DataFrame([], columns=['student_id', 'student_name']).astype({'student_id':'Int64', 'student_name':'object'})\",\"Subjects = pd.DataFrame([], columns=['subject_name']).astype({'subject_name':'object'})\",\"Examinations = pd.DataFrame([], columns=['student_id', 'subject_name']).astype({'student_id':'Int64', 'subject_name':'object'})\"],\"manual\":false,\"postgresql\":[\"\\nCreate table If Not Exists Students (student_id int, student_name varchar(20))\\n\",\"Create table If Not Exists Subjects (subject_name varchar(20))\",\"Create table If Not Exists Examinations (student_id int, subject_name varchar(20))\"],\"database_schema\":{\"Students\":{\"student_id\":\"INT\",\"student_name\":\"VARCHAR(20)\"},\"Subjects\":{\"subject_name\":\"VARCHAR(20)\"},\"Examinations\":{\"student_id\":\"INT\",\"subject_name\":\"VARCHAR(20)\"}}}",
|
||
"judgerAvailable": true,
|
||
"judgeType": "large",
|
||
"mysqlSchemas": [
|
||
"Create table If Not Exists Students (student_id int, student_name varchar(20))",
|
||
"Create table If Not Exists Subjects (subject_name varchar(20))",
|
||
"Create table If Not Exists Examinations (student_id int, subject_name varchar(20))",
|
||
"Truncate table Students",
|
||
"insert into Students (student_id, student_name) values ('1', 'Alice')",
|
||
"insert into Students (student_id, student_name) values ('2', 'Bob')",
|
||
"insert into Students (student_id, student_name) values ('13', 'John')",
|
||
"insert into Students (student_id, student_name) values ('6', 'Alex')",
|
||
"Truncate table Subjects",
|
||
"insert into Subjects (subject_name) values ('Math')",
|
||
"insert into Subjects (subject_name) values ('Physics')",
|
||
"insert into Subjects (subject_name) values ('Programming')",
|
||
"Truncate table Examinations",
|
||
"insert into Examinations (student_id, subject_name) values ('1', 'Math')",
|
||
"insert into Examinations (student_id, subject_name) values ('1', 'Physics')",
|
||
"insert into Examinations (student_id, subject_name) values ('1', 'Programming')",
|
||
"insert into Examinations (student_id, subject_name) values ('2', 'Programming')",
|
||
"insert into Examinations (student_id, subject_name) values ('1', 'Physics')",
|
||
"insert into Examinations (student_id, subject_name) values ('1', 'Math')",
|
||
"insert into Examinations (student_id, subject_name) values ('13', 'Math')",
|
||
"insert into Examinations (student_id, subject_name) values ('13', 'Programming')",
|
||
"insert into Examinations (student_id, subject_name) values ('13', 'Physics')",
|
||
"insert into Examinations (student_id, subject_name) values ('2', 'Math')",
|
||
"insert into Examinations (student_id, subject_name) values ('1', 'Math')"
|
||
],
|
||
"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\":{\"Students\":[\"student_id\",\"student_name\"],\"Subjects\":[\"subject_name\"],\"Examinations\":[\"student_id\",\"subject_name\"]},\"rows\":{\"Students\":[[1,\"Alice\"],[2,\"Bob\"],[13,\"John\"],[6,\"Alex\"]],\"Subjects\":[[\"Math\"],[\"Physics\"],[\"Programming\"]],\"Examinations\":[[1,\"Math\"],[1,\"Physics\"],[1,\"Programming\"],[2,\"Programming\"],[1,\"Physics\"],[1,\"Math\"],[13,\"Math\"],[13,\"Programming\"],[13,\"Physics\"],[2,\"Math\"],[1,\"Math\"]]}}",
|
||
"__typename": "QuestionNode"
|
||
}
|
||
}
|
||
} |