{ "data": { "question": { "questionId": "3921", "questionFrontendId": "3580", "categoryTitle": "Database", "boundTopicId": 3696226, "title": "Find Consistently Improving Employees", "titleSlug": "find-consistently-improving-employees", "content": "
Table: employees
\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| employee_id | int |\n| name | varchar |\n+-------------+---------+\nemployee_id is the unique identifier for this table.\nEach row contains information about an employee.\n\n\n
Table: performance_reviews
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| review_id | int |\n| employee_id | int |\n| review_date | date |\n| rating | int |\n+-------------+------+\nreview_id is the unique identifier for this table.\nEach row represents a performance review for an employee. The rating is on a scale of 1-5 where 5 is excellent and 1 is poor.\n\n\n
Write a solution to find employees who have consistently improved their performance over their last three reviews.
\n\n3
review to be considered3
reviews must show strictly increasing ratings (each review better than the previous)3
reviews based on review_date
for each employee3
reviewsReturn the result table ordered by improvement score in descending order, then by name in ascending order.
\n\nThe result format is in the following example.
\n\n\n
Example:
\n\nInput:
\n\nemployees table:
\n\n\n+-------------+----------------+\n| employee_id | name |\n+-------------+----------------+\n| 1 | Alice Johnson |\n| 2 | Bob Smith |\n| 3 | Carol Davis |\n| 4 | David Wilson |\n| 5 | Emma Brown |\n+-------------+----------------+\n\n\n
performance_reviews table:
\n\n\n+-----------+-------------+-------------+--------+\n| review_id | employee_id | review_date | rating |\n+-----------+-------------+-------------+--------+\n| 1 | 1 | 2023-01-15 | 2 |\n| 2 | 1 | 2023-04-15 | 3 |\n| 3 | 1 | 2023-07-15 | 4 |\n| 4 | 1 | 2023-10-15 | 5 |\n| 5 | 2 | 2023-02-01 | 3 |\n| 6 | 2 | 2023-05-01 | 2 |\n| 7 | 2 | 2023-08-01 | 4 |\n| 8 | 2 | 2023-11-01 | 5 |\n| 9 | 3 | 2023-03-10 | 1 |\n| 10 | 3 | 2023-06-10 | 2 |\n| 11 | 3 | 2023-09-10 | 3 |\n| 12 | 3 | 2023-12-10 | 4 |\n| 13 | 4 | 2023-01-20 | 4 |\n| 14 | 4 | 2023-04-20 | 4 |\n| 15 | 4 | 2023-07-20 | 4 |\n| 16 | 5 | 2023-02-15 | 3 |\n| 17 | 5 | 2023-05-15 | 2 |\n+-----------+-------------+-------------+--------+\n\n\n
Output:
\n\n\n+-------------+----------------+-------------------+\n| employee_id | name | improvement_score |\n+-------------+----------------+-------------------+\n| 2 | Bob Smith | 3 |\n| 1 | Alice Johnson | 2 |\n| 3 | Carol Davis | 2 |\n+-------------+----------------+-------------------+\n\n\n
Explanation:
\n\nThe output table is ordered by improvement_score in descending order, then by name in ascending order.
\n表:employees
\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| employee_id | int |\n| name | varchar |\n+-------------+---------+\nemployee_id 是这张表的唯一主键。\n每一行包含一名员工的信息。\n\n\n
表:performance_reviews
\n+-------------+------+\n| Column Name | Type |\n+-------------+------+\n| review_id | int |\n| employee_id | int |\n| review_date | date |\n| rating | int |\n+-------------+------+\nreview_id 是这张表的唯一主键。\n每一行表示一名员工的绩效评估。评分在 1-5 的范围内,5分代表优秀,1分代表较差。\n\n\n
编写一个解决方案,以找到在过去三次评估中持续提高绩效的员工。
\n\n3
次评估 才能被考虑3
次评估,评分必须 严格递增(每次评价都比上一次好)review_date
为每位员工分析最近的 3
次评估3
次评估中最后一次评分与最早一次评分之间的差值返回结果表以 进步分数 降序 排序,然后以 名字 升序 排序。
\n\n结果格式如下所示。
\n\n\n\n
示例:
\n\n输入:
\n\nemployees 表:
\n\n\n+-------------+----------------+\n| employee_id | name |\n+-------------+----------------+\n| 1 | Alice Johnson |\n| 2 | Bob Smith |\n| 3 | Carol Davis |\n| 4 | David Wilson |\n| 5 | Emma Brown |\n+-------------+----------------+\n\n\n
performance_reviews 表:
\n\n\n+-----------+-------------+-------------+--------+\n| review_id | employee_id | review_date | rating |\n+-----------+-------------+-------------+--------+\n| 1 | 1 | 2023-01-15 | 2 |\n| 2 | 1 | 2023-04-15 | 3 |\n| 3 | 1 | 2023-07-15 | 4 |\n| 4 | 1 | 2023-10-15 | 5 |\n| 5 | 2 | 2023-02-01 | 3 |\n| 6 | 2 | 2023-05-01 | 2 |\n| 7 | 2 | 2023-08-01 | 4 |\n| 8 | 2 | 2023-11-01 | 5 |\n| 9 | 3 | 2023-03-10 | 1 |\n| 10 | 3 | 2023-06-10 | 2 |\n| 11 | 3 | 2023-09-10 | 3 |\n| 12 | 3 | 2023-12-10 | 4 |\n| 13 | 4 | 2023-01-20 | 4 |\n| 14 | 4 | 2023-04-20 | 4 |\n| 15 | 4 | 2023-07-20 | 4 |\n| 16 | 5 | 2023-02-15 | 3 |\n| 17 | 5 | 2023-05-15 | 2 |\n+-----------+-------------+-------------+--------+\n\n\n
输出:
\n\n\n+-------------+----------------+-------------------+\n| employee_id | name | improvement_score |\n+-------------+----------------+-------------------+\n| 2 | Bob Smith | 3 |\n| 1 | Alice Johnson | 2 |\n| 3 | Carol Davis | 2 |\n+-------------+----------------+-------------------+\n\n\n
解释:
\n\n输出表以 improvement_score 降序排序,然后以 name 升序排序。
\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\":{\"employees\":[\"employee_id\",\"name\"],\"performance_reviews\":[\"review_id\",\"employee_id\",\"review_date\",\"rating\"]},\"rows\":{\"employees\":[[1,\"Alice Johnson\"],[2,\"Bob Smith\"],[3,\"Carol Davis\"],[4,\"David Wilson\"],[5,\"Emma Brown\"]],\"performance_reviews\":[[1,1,\"2023-01-15\",2],[2,1,\"2023-04-15\",3],[3,1,\"2023-07-15\",4],[4,1,\"2023-10-15\",5],[5,2,\"2023-02-01\",3],[6,2,\"2023-05-01\",2],[7,2,\"2023-08-01\",4],[8,2,\"2023-11-01\",5],[9,3,\"2023-03-10\",1],[10,3,\"2023-06-10\",2],[11,3,\"2023-09-10\",3],[12,3,\"2023-12-10\",4],[13,4,\"2023-01-20\",4],[14,4,\"2023-04-20\",4],[15,4,\"2023-07-20\",4],[16,5,\"2023-02-15\",3],[17,5,\"2023-05-15\",2]]}}",
"__typename": "QuestionNode"
}
}
}MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"