8000 Initial Commit · priyesh0453/SQL-LeetCode@cf2b12d · GitHub
[go: up one dir, main page]

Skip to content

Commit cf2b12d

Browse files
committed
Initial Commit
1 parent 03eef99 commit cf2b12d

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
Table: Patients
3+
4+
+--------------+---------+
5+
| Column Name | Type |
6+
+--------------+---------+
7+
| patient_id | int |
8+
| patient_name | varchar |
9+
| conditions | varchar |
10+
+--------------+---------+
11+
patient_id is the primary key for this table.
12+
'conditions' contains 0 or more code separated by spaces.
13+
This table contains information of the patients in the hospital.
14+
15+
16+
Required Query:
17+
18+
Report the patient_id, patient_name and conditions of the patients who have Type I Diabetes. Type I Diabetes always starts with DIAB1 prefix.
19+
20+
SQL Schema:
21+
22+
Create table If Not Exists Patients (patient_id int, patient_name varchar(30), conditions varchar(100))
23+
Truncate table Patients
24+
insert into Patients (patient_id, patient_name, conditions) values ('1', 'Daniel', 'YFEV COUGH')
25+
insert into Patients (patient_id, patient_name, conditions) values ('2', 'Alice', '')
26+
insert into Patients (patient_id, patient_name, conditions) values ('3', 'Bob', 'DIAB100 MYOP')
27+
insert into Patients (patient_id, patient_name, conditions) values ('4', 'George', 'ACNE DIAB100')
28+
insert into Patients (patient_id, patient_name, conditions) values ('5', 'Alain', 'DIAB201')
29+
30+
Example:
31+
32+
Input:
33+
Patients table:
34+
+------------+--------------+--------------+
35+
| patient_id | patient_name | conditions |
36+
+------------+--------------+--------------+
37+
| 1 | Daniel | YFEV COUGH |
38+
| 2 | Alice | |
39+
| 3 | Bob | DIAB100 MYOP |
40+
| 4 | George | ACNE DIAB100 |
41+
| 5 | Alain | DIAB201 |
42+
+------------+--------------+--------------+
43+
Output:
44+
+------------+--------------+--------------+
45+
| patient_id | patient_name | conditions |
46+
+------------+--------------+--------------+
47+
| 3 | Bob | DIAB100 MYOP |
48+
| 4 | George | ACNE DIAB100 |
49+
+------------+--------------+--------------+
50+
*/
51+
52+
-- Solution:
53+
SELECT *
54+
FROM Patients
55+
WHERE conditions LIKE "% DIAB1%" OR conditions LIKE "DIAB1%"

0 commit comments

Comments
 (0)
0