-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_analysis_performance_students.sql
277 lines (248 loc) · 8.03 KB
/
data_analysis_performance_students.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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
CREATE DATABASE performance;
USE performance;
ALTER TABLE students ADD COLUMN id_student INT PRIMARY KEY AUTO_INCREMENT;
DESCRIBE students;
-- 1.Average score in each subject.
SELECT
ROUND(AVG(math_score)),
ROUND(AVG(writing_score)),
ROUND(AVG(reading_score))
FROM
students
WHERE
math_score IS NOT NULL
AND writing_score IS NOT NULL
AND reading_score IS NOT NULL;
-- The average score per student is: in mathematics 66 out of 100, in writing 68 out of 100 and finally, in reading 69 out of 100.
-- 2.How many students took the test preparation course?
SELECT
test_preparation_course,
concat(round(count(test_preparation_course)/10,2),"%") as course_percentage
FROM
students
GROUP BY test_preparation_course;
-- 64.20% of students did not take the exam preparation course, while 35.80% did.
-- 3.Is there a relationship between the student doing a test preparation course and the score in the exams?
SELECT round(avg((math_score+writing_score+reading_score)/3)) as avg_total_score
from students
where test_preparation_course IS NOT NULL
AND test_preparation_course = 'none'
AND math_score IS NOT NULL
AND writing_score IS NOT NULL
AND reading_score IS NOT NULL;
-- The average score per subject from a student who did not take the preparation course is 65 out of 100.
SELECT
ROUND(AVG(math_score)),
ROUND(AVG(writing_score)),
ROUND(AVG(reading_score))
FROM
students
WHERE
test_preparation_course IS NOT NULL
AND test_preparation_course = 'none'
AND math_score IS NOT NULL
AND writing_score IS NOT NULL
AND reading_score IS NOT NULL;
-- The average score per student who did not take the course is: in math 64 out of 100, in writing 65 out of 100 and finally, in reading 67 out of 100.
SELECT round(avg((math_score+writing_score+reading_score)/3)) as avg_total_score
from students
where test_preparation_course IS NOT NULL
AND test_preparation_course = 'completed'
AND math_score IS NOT NULL
AND writing_score IS NOT NULL
AND reading_score IS NOT NULL;
-- The average score per subject from a student who took the preparation course is 73 out of 100.
SELECT
ROUND(AVG(math_score)),
ROUND(AVG(writing_score)),
ROUND(AVG(reading_score))
FROM
students
WHERE
test_preparation_course IS NOT NULL
AND test_preparation_course = 'completed'
AND math_score IS NOT NULL
AND writing_score IS NOT NULL
AND reading_score IS NOT NULL;
-- The average score per student who took the course is: in math 70 out of 100, in writing 74 out of 100 and finally, in reading 74 out of 100.
-- 4.Number of students by gender.
SELECT
gender, COUNT(gender)
FROM
students
GROUP BY gender
HAVING gender IS NOT NULL;
-- There are 518 female and 482 male students.
-- 5.Average score by gender.
SELECT round(avg((math_score+writing_score+reading_score)/3)) as avg_total_score
from students
where gender = "female"
AND math_score IS NOT NULL
AND writing_score IS NOT NULL
AND reading_score IS NOT NULL;
-- The average score per subject for a female student is 70 out of 100.
SELECT round(avg((math_score+writing_score+reading_score)/3)) as avg_total_score
from students
where gender = "male"
AND math_score IS NOT NULL
AND writing_score IS NOT NULL
AND reading_score IS NOT NULL;
-- The average score per subject for a male student is 66 out of 100.
-- 6.Average score per subject by gender.
SELECT
ROUND(AVG(math_score)) as avg_math,
ROUND(AVG(writing_score)) as avg_writing,
ROUND(AVG(reading_score)) as avg_reading
FROM
students
WHERE
gender IS NOT NULL
AND gender = 'female'
AND math_score IS NOT NULL
AND writing_score IS NOT NULL
AND reading_score IS NOT NULL;
-- The average score per female student is: in math 64 out of 100, in writing 72 out of 100 and finally, in reading 73 out of 100.
SELECT
ROUND(AVG(math_score)) as avg_math,
ROUND(AVG(writing_score)) as avg_writing,
ROUND(AVG(reading_score)) as avg_reading
FROM
students
WHERE
gender IS NOT NULL
AND gender = 'male'
AND math_score IS NOT NULL
AND writing_score IS NOT NULL
AND reading_score IS NOT NULL;
-- The average score per male student is: in math 69 out of 100, in writing 63 out of 100 and finally, in reading 65 out of 100.
-- 7.Student with the highest total score.
SELECT
id_student,
(math_score + writing_score + reading_score) AS total_score
FROM
students
ORDER BY total_score DESC;
-- The students with the highest total score are three, they also have a perfect score in all the exams. students with id: 101, 812 and 941.
-- 8.Student with the lowest total score.
SELECT
id_student,
(math_score + writing_score + reading_score) AS total_score
FROM
students
ORDER BY total_score ASC;
-- The student with the lowest total score in the exams is the student id: 60.
-- 9.What role did ethnicity and educational level from their parents play?
SELECT
ethnicity, parental_level_education
FROM
students
ORDER BY ethnicity ASC;
SELECT
ethnicity, COUNT(ethnicity) AS count_students
FROM
students
GROUP BY ethnicity
ORDER BY ethnicity ASC;
-- The group with most amount of students is the C with 319.
-- The group with less amount of students is the A with 89.
SELECT
parental_level_education, COUNT(parental_level_education)
FROM
students
GROUP BY parental_level_education;
-- Most of parents' education is some college.
-- The least amount of education they have is a master's degree.
SELECT
parental_level_education, COUNT(parental_level_education)
FROM
students
WHERE
ethnicity = 'group A'
GROUP BY parental_level_education;
-- Most parents' education in group A is some high school.
-- Most parents' least amount of education in group A is a master degree.
SELECT
parental_level_education, COUNT(parental_level_education)
FROM
students
WHERE
ethnicity = 'group B'
GROUP BY parental_level_education;
-- Most parents' education in group B is high school.
-- Most parents' least amount of education in group B is a master degree.
SELECT
parental_level_education, COUNT(parental_level_education)
FROM
students
WHERE
ethnicity = 'group C'
GROUP BY parental_level_education;
-- Most parents' education in group C is associate degree.
-- Most parents' least amount of education in group C is a master degree.
SELECT
parental_level_education, COUNT(parental_level_education)
FROM
students
WHERE
ethnicity = 'group D'
GROUP BY parental_level_education;
-- Most parents' education in group D is some college.
-- Most parents' least amount of education in group D is a master degree.
SELECT
parental_level_education, COUNT(parental_level_education)
FROM
students
WHERE
ethnicity = 'group E'
GROUP BY parental_level_education;
-- Most parents' education in group E is associate degree.
-- Most parents' least amount of education in group E is a master degree.
-- The least obtained level of parental education is a master degree, regardless of ethnicity group.
-- 10.How do ethnicity and lunch behave?
SELECT
lunch, COUNT(lunch)
FROM
students
GROUP BY lunch;
-- Most students access the standard lunch.
SELECT
lunch, COUNT(lunch)
FROM
students
WHERE
ethnicity = 'group A'
GROUP BY lunch;
-- Most students in group A access the standard lunch.
SELECT
lunch, COUNT(lunch)
FROM
students
WHERE
ethnicity = 'group B'
GROUP BY lunch;
-- Most students in group B access the standard lunch.
SELECT
lunch, COUNT(lunch)
FROM
students
WHERE
ethnicity = 'group C'
GROUP BY lunch;
-- Most students in group C access the standard lunch.
SELECT
lunch, COUNT(lunch)
FROM
students
WHERE
ethnicity = 'group D'
GROUP BY lunch;
-- Most students in group D access the standard lunch.
SELECT
lunch, COUNT(lunch)
FROM
students
WHERE
ethnicity = 'group E'
GROUP BY lunch;
-- Most students in group E access the standard lunch.
-- Most students, regardless of their group, have access to the standard lunch.