-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path034.sql
More file actions
35 lines (30 loc) · 892 Bytes
/
034.sql
File metadata and controls
35 lines (30 loc) · 892 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
/* Q: Show patient_id, attending_doctor_id, and diagnosis for admissions that match one of the two criteria:
1. patient_id is an odd number and attending_doctor_id is either 1, 5, or 19.
2. attending_doctor_id contains a 2 and the length of patient_id is 3 characters.
Table Info: admissions
+----------------------+----------+
| Column Name | Type |
+----------------------+----------+
| patient_id | INT |
| admission_date | DATE |
| discharge_date | DATE |
| diagnosis | TEXT |
| attending_doctor_id | INT |
+----------------------+----------+
*/
-- SOLUTION:
select
patient_id,
attending_doctor_id,
diagnosis
from admissions
where
(
patient_id % 2 != 0
and attending_doctor_id in(1,5,19)
)
or
(
attending_doctor_id like '%2%'
and length(patient_id) = 3
);