{ "data": { "question": { "questionId": "3767", "questionFrontendId": "3421", "categoryTitle": "Database", "boundTopicId": 3046795, "title": "Find Students Who Improved", "titleSlug": "find-students-who-improved", "content": "
Table: Scores
\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| student_id | int |\n| subject | varchar |\n| score | int |\n| exam_date | varchar |\n+-------------+---------+\n(student_id, subject, exam_date) is the primary key for this table.\nEach row contains information about a student's score in a specific subject on a particular exam date. score is between 0 and 100 (inclusive).\n\n\n
Write a solution to find the students who have shown improvement. A student is considered to have shown improvement if they meet both of these conditions:
\n\nReturn the result table ordered by student_id,
subject
in ascending order.
The result format is in the following example.
\n\n\n
Example:
\n\nInput:
\n\nScores table:
\n\n\n+------------+----------+-------+------------+\n| student_id | subject | score | exam_date |\n+------------+----------+-------+------------+\n| 101 | Math | 70 | 2023-01-15 |\n| 101 | Math | 85 | 2023-02-15 |\n| 101 | Physics | 65 | 2023-01-15 |\n| 101 | Physics | 60 | 2023-02-15 |\n| 102 | Math | 80 | 2023-01-15 |\n| 102 | Math | 85 | 2023-02-15 |\n| 103 | Math | 90 | 2023-01-15 |\n| 104 | Physics | 75 | 2023-01-15 |\n| 104 | Physics | 85 | 2023-02-15 |\n+------------+----------+-------+------------+\n\n\n
Output:
\n\n\n+------------+----------+-------------+--------------+\n| student_id | subject | first_score | latest_score |\n+------------+----------+-------------+--------------+\n| 101 | Math | 70 | 85 |\n| 102 | Math | 80 | 85 |\n| 104 | Physics | 75 | 85 |\n+------------+----------+-------------+--------------+\n\n\n
Explanation:
\n\nResult table is ordered by student_id, subject.
\n表:Scores
\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| student_id | int |\n| subject | varchar |\n| score | int |\n| exam_date | varchar |\n+-------------+---------+\n(student_id, subject, exam_date) 是这张表的主键。\n每一行包含有关学生在特定考试日期特定科目成绩的信息。分数范围从 0 到 100(包括边界)。\n\n\n
编写一个解决方案来查找 进步的学生。如果 同时 满足以下两个条件,则该学生被认为是进步的:
\n\n返回结果表以 student_id
,subject
升序 排序。
结果格式如下所示。
\n\n\n\n
示例:
\n\n输入:
\n\nScores 表:
\n\n\n+------------+----------+-------+------------+\n| student_id | subject | score | exam_date |\n+------------+----------+-------+------------+\n| 101 | Math | 70 | 2023-01-15 |\n| 101 | Math | 85 | 2023-02-15 |\n| 101 | Physics | 65 | 2023-01-15 |\n| 101 | Physics | 60 | 2023-02-15 |\n| 102 | Math | 80 | 2023-01-15 |\n| 102 | Math | 85 | 2023-02-15 |\n| 103 | Math | 90 | 2023-01-15 |\n| 104 | Physics | 75 | 2023-01-15 |\n| 104 | Physics | 85 | 2023-02-15 |\n+------------+----------+-------+------------+\n\n
出:
\n\n\n+------------+----------+-------------+--------------+\n| student_id | subject | first_score | latest_score |\n+------------+----------+-------------+--------------+\n| 101 | Math | 70 | 85 |\n| 102 | Math | 80 | 85 |\n| 104 | Physics | 75 | 85 |\n+------------+----------+-------------+--------------+\n\n\n
解释:
\n\n结果表以 student_id,subject 升序排序。
\n\\u7248\\u672c\\uff1a mssql server 2019.<\\/p>\"],\"oraclesql\":[\"Oracle\",\" Oracle Sql 11.2.<\\/p>\"],\"pythondata\":[\"Pandas\",\" Python 3.10 with Pandas 2.2.2 and NumPy 1.26.4<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\" PostgreSQL 16<\\/p>\"]}",
"book": null,
"isSubscribed": false,
"isDailyQuestion": false,
"dailyRecordStatus": null,
"editorType": "CKEDITOR",
"ugcQuestionId": null,
"style": "LEETCODE",
"exampleTestcases": "{\"headers\":{\"Scores\":[\"student_id\",\"subject\",\"score\",\"exam_date\"]},\"rows\":{\"Scores\":[[101,\"Math\",70,\"2023-01-15\"],[101,\"Math\",85,\"2023-02-15\"],[101,\"Physics\",65,\"2023-01-15\"],[101,\"Physics\",60,\"2023-02-15\"],[102,\"Math\",80,\"2023-01-15\"],[102,\"Math\",85,\"2023-02-15\"],[103,\"Math\",90,\"2023-01-15\"],[104,\"Physics\",75,\"2023-01-15\"],[104,\"Physics\",85,\"2023-02-15\"]]}}",
"__typename": "QuestionNode"
}
}
}MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"