-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path045.sql
More file actions
39 lines (31 loc) · 784 Bytes
/
045.sql
File metadata and controls
39 lines (31 loc) · 784 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
38
39
/* Q: Show patient_id, weight, height, isObese from the patients table.
Display isObese as a boolean 0 or 1.
Obese is defined as weight(kg)/(height(m)2) >= 30.
weight is in units kg.
height is in units cm.
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
patient_id,
weight,
height,
case
when weight / power(height/100.0, 2) >= 30 then 1
else 0
end as isObese
from patients;