-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcardio_train_query.sql
205 lines (172 loc) · 5.01 KB
/
cardio_train_query.sql
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
# Having noticed abnormally high body_mass_index, I noticed wrong entries in height_in_cm
UPDATE cardio_train_incidence
SET
height_in_cm = height_in_cm + 100
WHERE height_in_cm < 100;
# Compute body_mass_index again
UPDATE cardio_train_incidence
SET
body_mass_index = IFNULL(weight_in_kg /((height_in_cm/100) * (height_in_cm/100)), 0);
/* Calculate the age in years (add new column age_in_years)
Calculate the BMI (add new column body_mass_index)
Categorise different permutations of Lifestyle Habits (smoking, alcohol, active) in new column (lifestyle_habits)
1 : where smoker is False and alcohol is False and Active is False
2 : where smoker is False and alcohol is False and Active is True
3 : where smoker is False and alcohol is True and Active is False
4 : where smoker is False and alcohol is True and Active is True
5 : where smoker is True and alcohol is False and Active is False
6 : where smoker is True and alcohol is False and Active is True
7 : where smoker is True and alcohol is True and Active is False
8 : where smoker is True and alcohol is True and Active is True
Categorise different permutations of glucose and cholesterol ranking (normal, above normal and well above normal)
in new column (gluc_and_chol)
1 : where cholesterol_ranking = 1 and glucose_ranking = 1
2 : where cholesterol_ranking = 1 and glucose_ranking = 2
3 : where cholesterol_ranking = 1 and glucose_ranking = 3
4 : where cholesterol_ranking = 2 and glucose_ranking = 1
5 : where cholesterol_ranking = 2 and glucose_ranking = 2
6 : where cholesterol_ranking = 2 and glucose_ranking = 3
7 : where cholesterol_ranking = 3 and glucose_ranking = 1
8 : where cholesterol_ranking = 3 and glucose_ranking = 2
9 : where cholesterol_ranking = 3 and glucose_ranking = 3
Export table to use for multivariate analysis in jupyter notebook */
GRANT UPDATE ON cardio_train_incidence TO root@localhost;
UPDATE cardio_train_incidence
SET
lifestyle_habits = 1
WHERE
(smoker is False AND alcohol is False AND active is False);
UPDATE cardio_train_incidence
SET
lifestyle_habits = 2
WHERE
(smoker is False AND alcohol is False AND active is True);
UPDATE cardio_train_incidence
SET
lifestyle_habits = 3
WHERE
(smoker is False AND alcohol is True AND active is False);
UPDATE cardio_train_incidence
SET
lifestyle_habits = 4
WHERE
(smoker is False AND alcohol is True AND active is True);
UPDATE cardio_train_incidence
SET
lifestyle_habits = 5
WHERE
(smoker is True AND alcohol is False AND active is False);
UPDATE cardio_train_incidence
SET
lifestyle_habits = 6
WHERE
(smoker is True AND alcohol is False AND active is True);
UPDATE cardio_train_incidence
SET
lifestyle_habits = 7
WHERE
(smoker is True AND alcohol is True AND active is False);
UPDATE cardio_train_incidence
SET
lifestyle_habits = 8
WHERE
(smoker is True AND alcohol is True AND active is True);
# gluc_and_chol column
UPDATE cardio_train_incidence
SET
gluc_and_chol = 1
WHERE
(cholesterol_ranking = 1 AND glucose_ranking = 1);
UPDATE cardio_train_incidence
SET
gluc_and_chol = 2
WHERE
(cholesterol_ranking = 1 AND glucose_ranking = 2);
UPDATE cardio_train_incidence
SET
gluc_and_chol = 3
WHERE
(cholesterol_ranking = 1 AND glucose_ranking = 3);
UPDATE cardio_train_incidence
SET
gluc_and_chol = 4
WHERE
(cholesterol_ranking = 2 AND glucose_ranking = 1);
UPDATE cardio_train_incidence
SET
gluc_and_chol = 5
WHERE
(cholesterol_ranking = 2 AND glucose_ranking = 2);
UPDATE cardio_train_incidence
SET
gluc_and_chol = 6
WHERE
(cholesterol_ranking = 2 AND glucose_ranking = 3);
UPDATE cardio_train_incidence
SET
gluc_and_chol = 7
WHERE
(cholesterol_ranking = 3 AND glucose_ranking = 1);
UPDATE cardio_train_incidence
SET
gluc_and_chol = 8
WHERE
(cholesterol_ranking = 3 AND glucose_ranking = 2);
UPDATE cardio_train_incidence
SET
gluc_and_chol = 9
WHERE
(cholesterol_ranking = 3 AND glucose_ranking = 3);
SELECT *
FROM cardio_train_incidence;
DELETE FROM cardio_train_incidence
WHERE body_mass_index > 60.00;
SELECT
age_in_years,
glucose_ranking,
cholesterol_ranking,
smoker,
alcohol,
active
FROM
cardio_train_incidence
WHERE
bmi_ranking = 3 AND sex = 'female' AND cardio_condition is True;
SELECT
age_in_years,
glucose_ranking,
cholesterol_ranking,
smoker,
alcohol,
active
FROM
cardio_train_incidence
WHERE
bmi_ranking = 3 AND sex = 'male' AND cardio_condition is True;
SELECT
age_in_years,
glucose_ranking,
cholesterol_ranking,
smoker,
alcohol,
active
FROM cardio_train_incidence
WHERE bmi_ranking = 2 AND sex = 'female' AND cardio_condition is True;
SELECT
age_in_years,
glucose_ranking,
cholesterol_ranking,
smoker,
alcohol,
active
FROM cardio_train_incidence
WHERE bmi_ranking = 2 AND sex = 'male' AND cardio_condition is True;
SELECT
age_in_years,
glucose_ranking,
cholesterol_ranking,
smoker,
alcohol,
active
FROM cardio_train_incidence
WHERE bmi_ranking = 1 AND sex = 'female' AND cardio_condition is False;