https://leetcode.com/problems/patients-with-a-condition/description/
replace, substring, concat, left, right, lower, upper, trim, length, format, instr 정도만 알아도 SQL 데이터 변형에 큰 문제가 없겠지만, Regex 문법 까지 익숙해지면 빠른 전처리에 큰 도움이 될 것 같다.
Write a solution to find the patient_id, patient_name, and conditions of the patients who have Type I Diabetes. Type I Diabetes always starts with DIAB1 prefix.
Return the result table in any order.
The result format is in the following example.
Example 1:
Input:
Patients table:
+------------+--------------+--------------+
| patient_id | patient_name | conditions |
+------------+--------------+--------------+
| 1 | Daniel | YFEV COUGH |
| 2 | Alice | |
| 3 | Bob | DIAB100 MYOP |
| 4 | George | ACNE DIAB100 |
| 5 | Alain | DIAB201 |
+------------+--------------+--------------+
Output:
+------------+--------------+--------------+
| patient_id | patient_name | conditions |
+------------+--------------+--------------+
| 3 | Bob | DIAB100 MYOP |
| 4 | George | ACNE DIAB100 |
+------------+--------------+--------------+
Explanation: Bob and George both have a condition that starts with DIAB1.
# conditions 열에 'DIAB1'이라는 문자열을 포함하는 모든 행을 선택
SELECT *
FROM patients
WHERE conditions REGEXP '\\bDIAB1'
'sql > easy' 카테고리의 다른 글
1978. Employees Whose Manager Left the Company (0) | 2024.08.21 |
---|---|
1251. Average Selling Price (0) | 2024.06.03 |
1341. Movie Rating (0) | 2024.05.31 |
550. Game Play Analysis IV (0) | 2024.05.29 |
511. Game Play Analysis I (0) | 2024.03.30 |