-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path048.sql
More file actions
33 lines (27 loc) · 926 Bytes
/
048.sql
File metadata and controls
33 lines (27 loc) · 926 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
/* Q: Each admission costs $50 for patients without insurance, and $10 for patients with insurance. All patients with an even patient_id have insurance.
Give each patient a 'Yes' if they have insurance, and a 'No' if they don't have insurance. Add up the admission_total cost for each has_insurance group.
Table Info: admissions
+----------------------+----------+
| Column Name | Type |
+----------------------+----------+
| patient_id | INT |
| admission_date | DATE |
| discharge_date | DATE |
| diagnosis | TEXT |
| attending_doctor_id | INT |
+----------------------+----------+
*/
-- SOLUTION:
select
case
when patient_id % 2 = 0 then 'Yes'
else 'No'
end as has_insurance,
sum (
case
when patient_id % 2 = 0 then 10
else 50
end
) as cost_after_insurance
from admissions
group by has_insurance;