mirror of
https://gitee.com/coder-xiaomo/leetcode-problemset
synced 2025-09-06 07:51:41 +08:00
存量题库数据更新
This commit is contained in:
113
leetcode/problem/students-and-examinations.html
Normal file
113
leetcode/problem/students-and-examinations.html
Normal file
@@ -0,0 +1,113 @@
|
||||
<p>Table: <code>Students</code></p>
|
||||
|
||||
<pre>
|
||||
+---------------+---------+
|
||||
| Column Name | Type |
|
||||
+---------------+---------+
|
||||
| student_id | int |
|
||||
| student_name | varchar |
|
||||
+---------------+---------+
|
||||
student_id is the primary key (column with unique values) for this table.
|
||||
Each row of this table contains the ID and the name of one student in the school.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>Table: <code>Subjects</code></p>
|
||||
|
||||
<pre>
|
||||
+--------------+---------+
|
||||
| Column Name | Type |
|
||||
+--------------+---------+
|
||||
| subject_name | varchar |
|
||||
+--------------+---------+
|
||||
subject_name is the primary key (column with unique values) for this table.
|
||||
Each row of this table contains the name of one subject in the school.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>Table: <code>Examinations</code></p>
|
||||
|
||||
<pre>
|
||||
+--------------+---------+
|
||||
| Column Name | Type |
|
||||
+--------------+---------+
|
||||
| student_id | int |
|
||||
| subject_name | varchar |
|
||||
+--------------+---------+
|
||||
There is no primary key (column with unique values) for this table. It may contain duplicates.
|
||||
Each student from the Students table takes every course from the Subjects table.
|
||||
Each row of this table indicates that a student with ID student_id attended the exam of subject_name.
|
||||
</pre>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<p>Write a solution to find the number of times each student attended each exam.</p>
|
||||
|
||||
<p>Return the result table ordered by <code>student_id</code> and <code>subject_name</code>.</p>
|
||||
|
||||
<p>The result format is in the following example.</p>
|
||||
|
||||
<p> </p>
|
||||
<p><strong class="example">Example 1:</strong></p>
|
||||
|
||||
<pre>
|
||||
<strong>Input:</strong>
|
||||
Students table:
|
||||
+------------+--------------+
|
||||
| student_id | student_name |
|
||||
+------------+--------------+
|
||||
| 1 | Alice |
|
||||
| 2 | Bob |
|
||||
| 13 | John |
|
||||
| 6 | Alex |
|
||||
+------------+--------------+
|
||||
Subjects table:
|
||||
+--------------+
|
||||
| subject_name |
|
||||
+--------------+
|
||||
| Math |
|
||||
| Physics |
|
||||
| Programming |
|
||||
+--------------+
|
||||
Examinations table:
|
||||
+------------+--------------+
|
||||
| student_id | subject_name |
|
||||
+------------+--------------+
|
||||
| 1 | Math |
|
||||
| 1 | Physics |
|
||||
| 1 | Programming |
|
||||
| 2 | Programming |
|
||||
| 1 | Physics |
|
||||
| 1 | Math |
|
||||
| 13 | Math |
|
||||
| 13 | Programming |
|
||||
| 13 | Physics |
|
||||
| 2 | Math |
|
||||
| 1 | Math |
|
||||
+------------+--------------+
|
||||
<strong>Output:</strong>
|
||||
+------------+--------------+--------------+----------------+
|
||||
| student_id | student_name | subject_name | attended_exams |
|
||||
+------------+--------------+--------------+----------------+
|
||||
| 1 | Alice | Math | 3 |
|
||||
| 1 | Alice | Physics | 2 |
|
||||
| 1 | Alice | Programming | 1 |
|
||||
| 2 | Bob | Math | 1 |
|
||||
| 2 | Bob | Physics | 0 |
|
||||
| 2 | Bob | Programming | 1 |
|
||||
| 6 | Alex | Math | 0 |
|
||||
| 6 | Alex | Physics | 0 |
|
||||
| 6 | Alex | Programming | 0 |
|
||||
| 13 | John | Math | 1 |
|
||||
| 13 | John | Physics | 1 |
|
||||
| 13 | John | Programming | 1 |
|
||||
+------------+--------------+--------------+----------------+
|
||||
<strong>Explanation:</strong>
|
||||
The result table should contain all students and all subjects.
|
||||
Alice attended the Math exam 3 times, the Physics exam 2 times, and the Programming exam 1 time.
|
||||
Bob attended the Math exam 1 time, the Programming exam 1 time, and did not attend the Physics exam.
|
||||
Alex did not attend any exams.
|
||||
John attended the Math exam 1 time, the Physics exam 1 time, and the Programming exam 1 time.
|
||||
</pre>
|
Reference in New Issue
Block a user