1
0
mirror of https://gitee.com/coder-xiaomo/leetcode-problemset synced 2025-09-06 16:01:41 +08:00
Code Issues Projects Releases Wiki Activity GitHub Gitee
Files
leetcode-problemset/leetcode-cn/originData/find-consistently-improving-employees.json
2025-06-18 01:10:28 +08:00

111 lines
20 KiB
JSON
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

{
"data": {
"question": {
"questionId": "3921",
"questionFrontendId": "3580",
"categoryTitle": "Database",
"boundTopicId": 3696226,
"title": "Find Consistently Improving Employees",
"titleSlug": "find-consistently-improving-employees",
"content": "<p>Table: <code>employees</code></p>\n\n<pre>\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</pre>\n\n<p>Table: <code>performance_reviews</code></p>\n\n<pre>\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</pre>\n\n<p>Write a solution to find employees who have consistently improved their performance over <strong>their last three reviews</strong>.</p>\n\n<ul>\n\t<li>An employee must have <strong>at least </strong><code>3</code><strong> review</strong> to be considered</li>\n\t<li>The employee&#39;s <strong>last </strong><code>3</code><strong> reviews</strong> must show <strong>strictly increasing ratings</strong> (each review better than the previous)</li>\n\t<li>Use the most recent <code>3</code> reviews based on <code>review_date</code> for each employee</li>\n\t<li>Calculate the <strong>improvement score</strong> as the difference between the latest rating and the earliest rating among the last <code>3</code> reviews</li>\n</ul>\n\n<p>Return <em>the result table ordered by <strong>improvement score</strong> in <strong>descending</strong> order, then by <strong>name</strong> in <strong>ascending</strong> order</em>.</p>\n\n<p>The result format is in the following example.</p>\n\n<p>&nbsp;</p>\n<p><strong class=\"example\">Example:</strong></p>\n\n<div class=\"example-block\">\n<p><strong>Input:</strong></p>\n\n<p>employees table:</p>\n\n<pre class=\"example-io\">\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</pre>\n\n<p>performance_reviews table:</p>\n\n<pre class=\"example-io\">\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</pre>\n\n<p><strong>Output:</strong></p>\n\n<pre class=\"example-io\">\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</pre>\n\n<p><strong>Explanation:</strong></p>\n\n<ul>\n\t<li><strong>Alice Johnson (employee_id = 1):</strong>\n\n\t<ul>\n\t\t<li>Has 4 reviews with ratings: 2, 3, 4, 5</li>\n\t\t<li>Last 3 reviews (by date): 2023-04-15 (3), 2023-07-15 (4), 2023-10-15 (5)</li>\n\t\t<li>Ratings are strictly increasing: 3 &rarr; 4 &rarr; 5</li>\n\t\t<li>Improvement score: 5 - 3 = 2</li>\n\t</ul>\n\t</li>\n\t<li><strong>Carol Davis (employee_id = 3):</strong>\n\t<ul>\n\t\t<li>Has 4 reviews with ratings: 1, 2, 3, 4</li>\n\t\t<li>Last 3 reviews (by date): 2023-06-10 (2), 2023-09-10 (3), 2023-12-10 (4)</li>\n\t\t<li>Ratings are strictly increasing: 2 &rarr; 3 &rarr; 4</li>\n\t\t<li>Improvement score: 4 - 2 = 2</li>\n\t</ul>\n\t</li>\n\t<li><strong>Bob Smith (employee_id = 2):</strong>\n\t<ul>\n\t\t<li>Has 4 reviews with ratings: 3, 2, 4, 5</li>\n\t\t<li>Last 3 reviews (by date): 2023-05-01 (2), 2023-08-01 (4), 2023-11-01 (5)</li>\n\t\t<li>Ratings are strictly increasing: 2 &rarr; 4 &rarr; 5</li>\n\t\t<li>Improvement score: 5 - 2 = 3</li>\n\t</ul>\n\t</li>\n\t<li><strong>Employees not included:</strong>\n\t<ul>\n\t\t<li>David Wilson (employee_id = 4): Last 3 reviews are all 4 (no improvement)</li>\n\t\t<li>Emma Brown (employee_id = 5): Only has 2 reviews (needs at least 3)</li>\n\t</ul>\n\t</li>\n</ul>\n\n<p>The output table is ordered by improvement_score in descending order, then by name in ascending order.</p>\n</div>\n",
"translatedTitle": "寻找持续进步的员工",
"translatedContent": "<p>表:<code>employees</code></p>\n\n<pre>\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| employee_id | int |\n| name | varchar |\n+-------------+---------+\nemployee_id 是这张表的唯一主键。\n每一行包含一名员工的信息。\n</pre>\n\n<p>表:<code>performance_reviews</code></p>\n\n<pre>\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</pre>\n\n<p>编写一个解决方案,以找到在过去三次评估中持续提高绩效的员工。</p>\n\n<ul>\n\t<li>员工 <strong>至少需要</strong> <code>3</code>&nbsp;<strong>次评估&nbsp;</strong>才能被考虑</li>\n\t<li>员工过去的&nbsp;<code>3</code> 次评估,评分必须&nbsp;<strong>严格递增</strong>(每次评价都比上一次好)</li>\n\t<li>根据 <code>review_date</code> 为每位员工分析最近的 <code>3</code> 次评估</li>\n\t<li><strong>进步分数</strong> 为最后 <code>3</code> 次评估中最后一次评分与最早一次评分之间的差值</li>\n</ul>\n\n<p>返回结果表以<em>&nbsp;</em><strong>进步分数 降序</strong>&nbsp;排序,然后以&nbsp;<strong>名字</strong>&nbsp;<strong>升序</strong>&nbsp;排序。</p>\n\n<p>结果格式如下所示。</p>\n\n<p>&nbsp;</p>\n\n<p><strong class=\"example\">示例:</strong></p>\n\n<div class=\"example-block\">\n<p><strong>输入:</strong></p>\n\n<p>employees 表:</p>\n\n<pre class=\"example-io\">\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</pre>\n\n<p>performance_reviews 表:</p>\n\n<pre class=\"example-io\">\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</pre>\n\n<p><strong>输出:</strong></p>\n\n<pre class=\"example-io\">\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</pre>\n\n<p><strong>解释:</strong></p>\n\n<ul>\n\t<li><strong>Alice Johnson (employee_id = 1)</strong>\n\n\t<ul>\n\t\t<li>有 4 次评估分数2, 3, 4, 5</li>\n\t\t<li>最后 3 次评估按日期2023-04-15 (3), 2023-07-15 (4), 2023-10-15 (5)</li>\n\t\t<li>评分严格递增3 → 4 → 5</li>\n\t\t<li>进步分数5 - 3 = 2</li>\n\t</ul>\n\t</li>\n\t<li><strong>Carol Davis (employee_id = 3)</strong>\n\t<ul>\n\t\t<li>有 4 次评估分数1, 2, 3, 4</li>\n\t\t<li>最后 3 次评估按日期2023-06-10 (2)2023-09-10 (3)2023-12-10 (4)</li>\n\t\t<li>评分严格递增2 → 3 → 4</li>\n\t\t<li>进步分数4 - 2 = 2</li>\n\t</ul>\n\t</li>\n\t<li><strong>Bob Smith (employee_id = 2)</strong>\n\t<ul>\n\t\t<li>有 4 次评估分数3245</li>\n\t\t<li>最后 3 次评估按日期2023-05-01 (2)2023-08-01 (4)2023-11-01 (5)</li>\n\t\t<li>评分严格递增2 → 4 → 5</li>\n\t\t<li>进步分数5 - 2 = 3</li>\n\t</ul>\n\t</li>\n\t<li><strong>未包含的员工:</strong>\n\t<ul>\n\t\t<li>David Wilson (employee_id = 4):之前 3 次评估都是 4 分(没有进步)</li>\n\t\t<li>Emma Brown (employee_id = 5):只有 2 次评估(需要至少 3 次)</li>\n\t</ul>\n\t</li>\n</ul>\n\n<p>输出表以 improvement_score 降序排序,然后以 name 升序排序。</p>\n</div>\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_consistently_improving_employees(employees: pd.DataFrame, performance_reviews: pd.DataFrame) -> pd.DataFrame:\n ",
"__typename": "CodeSnippetNode"
},
{
"lang": "PostgreSQL",
"langSlug": "postgresql",
"code": "-- Write your PostgreSQL query statement below",
"__typename": "CodeSnippetNode"
}
],
"stats": "{\"totalAccepted\": \"204\", \"totalSubmission\": \"303\", \"totalAcceptedRaw\": 204, \"totalSubmissionRaw\": 303, \"acRate\": \"67.3%\"}",
"hints": [],
"solution": null,
"status": null,
"sampleTestCase": "{\"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]]}}",
"metaData": "{\"mysql\":[\"CREATE TABLE employees (\\n employee_id INT,\\n name VARCHAR(255)\\n)\",\"CREATE TABLE performance_reviews (\\n review_id INT,\\n employee_id INT,\\n review_date DATE,\\n rating INT\\n)\"],\"mssql\":[\"CREATE TABLE employees (\\n employee_id INT,\\n name VARCHAR(255)\\n)\",\"CREATE TABLE performance_reviews (\\n review_id INT,\\n employee_id INT,\\n review_date DATE,\\n rating INT\\n)\"],\"oraclesql\":[\"CREATE TABLE employees (\\n employee_id NUMBER,\\n name VARCHAR2(255)\\n)\",\"CREATE TABLE performance_reviews (\\n review_id NUMBER,\\n employee_id NUMBER,\\n review_date DATE,\\n rating NUMBER\\n)\",\"ALTER SESSION SET nls_date_format='YYYY-MM-DD'\"],\"database\":true,\"name\":\"find_consistently_improving_employees\",\"postgresql\":[\"CREATE TABLE employees (\\n employee_id INTEGER,\\n name VARCHAR(255)\\n);\\n\",\"CREATE TABLE performance_reviews (\\n review_id INTEGER,\\n employee_id INTEGER,\\n review_date DATE,\\n rating NUMERIC\\n);\\n\"],\"pythondata\":[\"employees = pd.DataFrame({\\n 'employee_id': pd.Series(dtype='int'),\\n 'name': pd.Series(dtype='str')\\n})\",\"performance_reviews = pd.DataFrame({\\n 'review_id': pd.Series(dtype='int'),\\n 'employee_id': pd.Series(dtype='int'),\\n 'review_date': pd.Series(dtype='datetime64[ns]'),\\n 'rating': pd.Series(dtype='float') # Use float to accommodate decimal ratings\\n})\"],\"database_schema\":{\"employees\":{\"employee_id\":\"INT\",\"name\":\"VARCHAR(255)\"},\"performance_reviews\":{\"review_id\":\"INT\",\"employee_id\":\"INT\",\"review_date\":\"DATE\",\"rating\":\"INT\"}}}",
"judgerAvailable": true,
"judgeType": "large",
"mysqlSchemas": [
"CREATE TABLE employees (\n employee_id INT,\n name VARCHAR(255)\n)",
"CREATE TABLE performance_reviews (\n review_id INT,\n employee_id INT,\n review_date DATE,\n rating INT\n)",
"Truncate table employees",
"insert into employees (employee_id, name) values ('1', 'Alice Johnson')",
"insert into employees (employee_id, name) values ('2', 'Bob Smith')",
"insert into employees (employee_id, name) values ('3', 'Carol Davis')",
"insert into employees (employee_id, name) values ('4', 'David Wilson')",
"insert into employees (employee_id, name) values ('5', 'Emma Brown')",
"Truncate table performance_reviews",
"insert into performance_reviews (review_id, employee_id, review_date, rating) values ('1', '1', '2023-01-15', '2')",
"insert into performance_reviews (review_id, employee_id, review_date, rating) values ('2', '1', '2023-04-15', '3')",
"insert into performance_reviews (review_id, employee_id, review_date, rating) values ('3', '1', '2023-07-15', '4')",
"insert into performance_reviews (review_id, employee_id, review_date, rating) values ('4', '1', '2023-10-15', '5')",
"insert into performance_reviews (review_id, employee_id, review_date, rating) values ('5', '2', '2023-02-01', '3')",
"insert into performance_reviews (review_id, employee_id, review_date, rating) values ('6', '2', '2023-05-01', '2')",
"insert into performance_reviews (review_id, employee_id, review_date, rating) values ('7', '2', '2023-08-01', '4')",
"insert into performance_reviews (review_id, employee_id, review_date, rating) values ('8', '2', '2023-11-01', '5')",
"insert into performance_reviews (review_id, employee_id, review_date, rating) values ('9', '3', '2023-03-10', '1')",
"insert into performance_reviews (review_id, employee_id, review_date, rating) values ('10', '3', '2023-06-10', '2')",
"insert into performance_reviews (review_id, employee_id, review_date, rating) values ('11', '3', '2023-09-10', '3')",
"insert into performance_reviews (review_id, employee_id, review_date, rating) values ('12', '3', '2023-12-10', '4')",
"insert into performance_reviews (review_id, employee_id, review_date, rating) values ('13', '4', '2023-01-20', '4')",
"insert into performance_reviews (review_id, employee_id, review_date, rating) values ('14', '4', '2023-04-20', '4')",
"insert into performance_reviews (review_id, employee_id, review_date, rating) values ('15', '4', '2023-07-20', '4')",
"insert into performance_reviews (review_id, employee_id, review_date, rating) values ('16', '5', '2023-02-15', '3')",
"insert into performance_reviews (review_id, employee_id, review_date, rating) values ('17', '5', '2023-05-15', '2')"
],
"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.2.2 and NumPy 1.26.4<\\/p>\"],\"postgresql\":[\"PostgreSQL\",\"<p>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"
}
}
}