-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path023.sql
More file actions
37 lines (30 loc) · 961 Bytes
/
023.sql
File metadata and controls
37 lines (30 loc) · 961 Bytes
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
33
34
35
36
37
/* Q: Show first and last name, allergies from patients which have allergies to either 'Penicillin' or 'Morphine'. Show results ordered ascending by allergies then by first_name then by last_name.
Table Info: patients
+--------------+----------+
| Column Name | Type |
+--------------+----------+
| patient_id | INT |
| first_name | TEXT |
| last_name | TEXT |
| gender | CHAR(1) |
| birth_date | DATE |
| city | TEXT |
| province_id | CHAR(2) |
| allergies | TEXT |
| height | INT |
| weight | INT |
+--------------+----------+
*/
-- SOLUTION:
select first_name, last_name, allergies
from patients
where allergies in('Penicillin', 'Morphine')
order by allergies, first_name, last_name;
-- another solution
select first_name, last_name, allergies
from patients
where allergies = 'Penicillin' or allergies = 'Morphine'
order by
allergies asc,
first_name asc,
last_name asc;