-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1527. Patients With a Condition.sql
More file actions
32 lines (26 loc) · 1.04 KB
/
1527. Patients With a Condition.sql
File metadata and controls
32 lines (26 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
-- Write an SQL query to report the patient_id, patient_name all conditions of patients who have Type I Diabetes. Type I Diabetes always starts with DIAB1 prefix
--Solution1
SELECT * FROM Patients
WHERE conditions LIKE 'DIAB1%' OR
conditions LIKE '% DIAB1%'
--Solution2
SELECT * FROM Patients
WHERE conditions REGEXP '^DIAB1| DIAB1';
/* 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 |
+------------+--------------+--------------+ */