-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path046.sql
More file actions
62 lines (52 loc) · 1.48 KB
/
046.sql
File metadata and controls
62 lines (52 loc) · 1.48 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/* Q: Show patient_id, first_name, last_name, and attending doctor's specialty.
Show only the patients who has a diagnosis as 'Epilepsy' and the doctor's first name is 'Lisa'
Check patients, admissions, and doctors tables for required information.
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 |
+--------------+----------+
Table Info: admissions
+----------------------+----------+
| Column Name | Type |
+----------------------+----------+
| patient_id | INT |
| admission_date | DATE |
| discharge_date | DATE |
| diagnosis | TEXT |
| attending_doctor_id | INT |
+----------------------+----------+
Table Info: doctors
+------------+----------+
| Column | Type |
+------------+----------+
| doctor_id | INT |
| first_name | TEXT |
| last_name | TEXT |
| specialty | TEXT |
+------------+----------+
*/
-- SOLUTION:
select
p.patient_id,
p.first_name,
p.last_name,
d.specialty
from patients p
join admissions a
on p.patient_id = a.patient_id
join doctors d
on a.attending_doctor_id = d.doctor_id
where
a.diagnosis = 'Epilepsy'
and d.first_name = 'Lisa';