{ "data": { "question": { "questionId": "3932", "questionFrontendId": "3586", "categoryTitle": "Database", "boundTopicId": 3701001, "title": "Find COVID Recovery Patients", "titleSlug": "find-covid-recovery-patients", "content": "
Table: patients
\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| patient_id | int |\n| patient_name| varchar |\n| age | int |\n+-------------+---------+\npatient_id is the unique identifier for this table.\nEach row contains information about a patient.\n\n\n
Table: covid_tests
\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| test_id | int |\n| patient_id | int |\n| test_date | date |\n| result | varchar |\n+-------------+---------+\ntest_id is the unique identifier for this table.\nEach row represents a COVID test result. The result can be Positive, Negative, or Inconclusive.\n\n\n
Write a solution to find patients who have recovered from COVID - patients who tested positive but later tested negative.
\n\nReturn the result table ordered by recovery_time
in ascending order, then by patient_name
in ascending order.
The result format is in the following example.
\n\n\n
Example:
\n\nInput:
\n\npatients table:
\n\n\n+------------+--------------+-----+\n| patient_id | patient_name | age |\n+------------+--------------+-----+\n| 1 | Alice Smith | 28 |\n| 2 | Bob Johnson | 35 |\n| 3 | Carol Davis | 42 |\n| 4 | David Wilson | 31 |\n| 5 | Emma Brown | 29 |\n+------------+--------------+-----+\n\n\n
covid_tests table:
\n\n\n+---------+------------+------------+--------------+\n| test_id | patient_id | test_date | result |\n+---------+------------+------------+--------------+\n| 1 | 1 | 2023-01-15 | Positive |\n| 2 | 1 | 2023-01-25 | Negative |\n| 3 | 2 | 2023-02-01 | Positive |\n| 4 | 2 | 2023-02-05 | Inconclusive |\n| 5 | 2 | 2023-02-12 | Negative |\n| 6 | 3 | 2023-01-20 | Negative |\n| 7 | 3 | 2023-02-10 | Positive |\n| 8 | 3 | 2023-02-20 | Negative |\n| 9 | 4 | 2023-01-10 | Positive |\n| 10 | 4 | 2023-01-18 | Positive |\n| 11 | 5 | 2023-02-15 | Negative |\n| 12 | 5 | 2023-02-20 | Negative |\n+---------+------------+------------+--------------+\n\n\n
Output:
\n\n\n+------------+--------------+-----+---------------+\n| patient_id | patient_name | age | recovery_time |\n+------------+--------------+-----+---------------+\n| 1 | Alice Smith | 28 | 10 |\n| 3 | Carol Davis | 42 | 10 |\n| 2 | Bob Johnson | 35 | 11 |\n+------------+--------------+-----+---------------+\n\n\n
Explanation:
\n\nOutput table is ordered by recovery_time in ascending order, and then by patient_name in ascending order.
\n表:patients
\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| patient_id | int |\n| patient_name| varchar |\n| age | int |\n+-------------+---------+\npatient_id 是这张表的唯一主键。\n每一行表示一个患者的信息。\n\n\n
表:covid_tests
\n+-------------+---------+\n| Column Name | Type |\n+-------------+---------+\n| test_id | int |\n| patient_id | int |\n| test_date | date |\n| result | varchar |\n+-------------+---------+\ntest_id 是这张表的唯一主键。\n每一行代表一个 COVID 检测结果。结果可以是阳性、阴性或不确定。\n\n\n
编写一个解决方案以找到从 COVID 中康复的患者——那些曾经检测呈阳性但后来检测呈阴性的患者。
\n\n返回结果表以 recovery_time
升序 排序,然后以 patient_name
升序 排序。
结果格式如下所示。
\n\n\n\n
示例:
\n\n输入:
\n\npatients 表:
\n\n\n+------------+--------------+-----+\n| patient_id | patient_name | age |\n+------------+--------------+-----+\n| 1 | Alice Smith | 28 |\n| 2 | Bob Johnson | 35 |\n| 3 | Carol Davis | 42 |\n| 4 | David Wilson | 31 |\n| 5 | Emma Brown | 29 |\n+------------+--------------+-----+\n\n\n
covid_tests 表:
\n\n\n+---------+------------+------------+--------------+\n| test_id | patient_id | test_date | result |\n+---------+------------+------------+--------------+\n| 1 | 1 | 2023-01-15 | Positive |\n| 2 | 1 | 2023-01-25 | Negative |\n| 3 | 2 | 2023-02-01 | Positive |\n| 4 | 2 | 2023-02-05 | Inconclusive |\n| 5 | 2 | 2023-02-12 | Negative |\n| 6 | 3 | 2023-01-20 | Negative |\n| 7 | 3 | 2023-02-10 | Positive |\n| 8 | 3 | 2023-02-20 | Negative |\n| 9 | 4 | 2023-01-10 | Positive |\n| 10 | 4 | 2023-01-18 | Positive |\n| 11 | 5 | 2023-02-15 | Negative |\n| 12 | 5 | 2023-02-20 | Negative |\n+---------+------------+------------+--------------+\n\n\n
输出:
\n\n\n+------------+--------------+-----+---------------+\n| patient_id | patient_name | age | recovery_time |\n+------------+--------------+-----+---------------+\n| 1 | Alice Smith | 28 | 10 |\n| 3 | Carol Davis | 42 | 10 |\n| 2 | Bob Johnson | 35 | 11 |\n+------------+--------------+-----+---------------+\n\n\n
解释:
\n\n输出表以 recovery_time 升序排序,然后以 patient_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\":{\"patients\":[\"patient_id\",\"patient_name\",\"age\"],\"covid_tests\":[\"test_id\",\"patient_id\",\"test_date\",\"result\"]},\"rows\":{\"patients\":[[1,\"Alice Smith\",28],[2,\"Bob Johnson\",35],[3,\"Carol Davis\",42],[4,\"David Wilson\",31],[5,\"Emma Brown\",29]],\"covid_tests\":[[1,1,\"2023-01-15\",\"Positive\"],[2,1,\"2023-01-25\",\"Negative\"],[3,2,\"2023-02-01\",\"Positive\"],[4,2,\"2023-02-05\",\"Inconclusive\"],[5,2,\"2023-02-12\",\"Negative\"],[6,3,\"2023-01-20\",\"Negative\"],[7,3,\"2023-02-10\",\"Positive\"],[8,3,\"2023-02-20\",\"Negative\"],[9,4,\"2023-01-10\",\"Positive\"],[10,4,\"2023-01-18\",\"Positive\"],[11,5,\"2023-02-15\",\"Negative\"],[12,5,\"2023-02-20\",\"Negative\"]]}}",
"__typename": "QuestionNode"
}
}
}MySQL 8.0<\\/code><\\/p>\"],\"mssql\":[\"MS SQL Server\",\"