Description
Write a SQL query to find patients with Type I Diabetes (condition starts with 'DIAB1'). Return patient_id, patient_name, conditions.
Table:
patients| Column | Type |
|---|---|
| patient_id | INT |
| patient_name | TEXT |
| conditions | TEXT |
Examples
Input:
CREATE TABLE patients (patient_id INT, patient_name TEXT, conditions TEXT); INSERT INTO patients VALUES (1, 'Alice', 'DIAB100 COLD'), (2, 'Bob', 'FLU'), (3, 'Carol', 'ASTHMA');Output:
1|Alice|DIAB100 COLDExplanation:
Only Alice has a condition starting with 'DIAB1' (DIAB100). Bob and Carol don't have any DIAB1 conditions.
Input:
CREATE TABLE patients (patient_id INT, patient_name TEXT, conditions TEXT); INSERT INTO patients VALUES (4, 'Diana', 'HYPERTENSION DIAB1'), (5, 'Emma', 'DIAB2 ASTHMA'), (6, 'Frank', 'DIAB111 MIGRAINE');Output:
4|Diana|HYPERTENSION DIAB1
6|Frank|DIAB111 MIGRAINEExplanation:
Diana has 'DIAB1' condition and Frank has 'DIAB111' condition (both start with 'DIAB1'). Emma has 'DIAB2' which doesn't start with 'DIAB1' so is excluded.
Input:
CREATE TABLE patients (patient_id INT, patient_name TEXT, conditions TEXT); INSERT INTO patients VALUES (7, 'Grace', 'DIABETES DIAB199'), (8, 'Henry', 'PREDIAB1 OBESITY'), (9, 'Iris', 'DIAB1TYPE1');Output:
7|Grace|DIABETES DIAB199
9|Iris|DIAB1TYPE1Explanation:
Grace has 'DIAB199' and Iris has 'DIAB1TYPE1' (both contain conditions starting with 'DIAB1'). Henry's 'PREDIAB1' doesn't start with 'DIAB1', it starts with 'PREDIAB1', so is excluded.
Constraints
- •
Use LIKE with pattern