{ "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
\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\n\n\n

Return the result table ordered by student_id, subject in ascending order.

\n\n

The result format is in the following example.

\n\n

 

\n

Example:

\n\n
\n

Input:

\n\n

Scores 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\n\n\n

Result table is ordered by student_id, subject.

\n
\n", "translatedTitle": "查找进步的学生", "translatedContent": "

表:Scores

\n\n
\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\n\n

返回结果表以 student_idsubject 升序 排序。

\n\n

结果格式如下所示。

\n\n

 

\n\n

示例:

\n\n
\n

输入:

\n\n

Scores 表:

\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\n\n

结果表以 student_id,subject 升序排序。

\n
\n", "isPaidOnly": false, "difficulty": "Medium", "likes": 0, "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, \"cangjie\": 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 find_students_who_improved(scores: pd.DataFrame) -> pd.DataFrame:\n ", "__typename": "CodeSnippetNode" }, { "lang": "PostgreSQL", "langSlug": "postgresql", "code": "-- Write your PostgreSQL query statement below", "__typename": "CodeSnippetNode" } ], "stats": "{\"totalAccepted\": \"249\", \"totalSubmission\": \"404\", \"totalAcceptedRaw\": 249, \"totalSubmissionRaw\": 404, \"acRate\": \"61.6%\"}", "hints": [], "solution": null, "status": null, "sampleTestCase": "{\"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\"]]}}", "metaData": "{\"mysql\":[\"CREATE TABLE Scores (\\n student_id INT,\\n subject VARCHAR(50),\\n score INT,\\n exam_date VARCHAR(10)\\n)\"],\"mssql\":[\"CREATE TABLE Scores (\\n student_id INT,\\n subject VARCHAR(50),\\n score INT,\\n exam_date VARCHAR(10)\\n)\"],\"oraclesql\":[\"CREATE TABLE Scores (\\n student_id NUMBER,\\n subject VARCHAR2(50),\\n score NUMBER,\\n exam_date VARCHAR2(10)\\n)\"],\"database\":true,\"name\":\"find_students_who_improved\",\"postgresql\":[\"CREATE TABLE Scores (\\n student_id INT,\\n subject VARCHAR(50),\\n score INT,\\n exam_date VARCHAR(10)\\n);\\n\"],\"pythondata\":[\"Scores = pd.DataFrame({\\\"student_id\\\": pd.Series(dtype=\\\"int\\\"),\\n \\\"subject\\\": pd.Series(dtype=\\\"str\\\"),\\n \\\"score\\\": pd.Series(dtype=\\\"int\\\"),\\n \\\"exam_date\\\": pd.Series(dtype=\\\"str\\\")})\"],\"database_schema\":{\"Scores\":{\"student_id\":\"INT\",\"subject\":\"VARCHAR(50)\",\"score\":\"INT\",\"exam_date\":\"VARCHAR(10)\"}}}", "judgerAvailable": true, "judgeType": "large", "mysqlSchemas": [ "CREATE TABLE Scores (\n student_id INT,\n subject VARCHAR(50),\n score INT,\n exam_date VARCHAR(10)\n)", "Truncate table Scores", "insert into Scores (student_id, subject, score, exam_date) values ('101', 'Math', '70', '2023-01-15')", "insert into Scores (student_id, subject, score, exam_date) values ('101', 'Math', '85', '2023-02-15')", "insert into Scores (student_id, subject, score, exam_date) values ('101', 'Physics', '65', '2023-01-15')", "insert into Scores (student_id, subject, score, exam_date) values ('101', 'Physics', '60', '2023-02-15')", "insert into Scores (student_id, subject, score, exam_date) values ('102', 'Math', '80', '2023-01-15')", "insert into Scores (student_id, subject, score, exam_date) values ('102', 'Math', '85', '2023-02-15')", "insert into Scores (student_id, subject, score, exam_date) values ('103', 'Math', '90', '2023-01-15')", "insert into Scores (student_id, subject, score, exam_date) values ('104', 'Physics', '75', '2023-01-15')", "insert into Scores (student_id, subject, score, exam_date) values ('104', 'Physics', '85', '2023-02-15')" ], "enableRunCode": true, "envInfo": "{\"mysql\":[\"MySQL\",\"

\\u7248\\u672c\\uff1aMySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"

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" } } }