You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: sqlzoo/8+_NUMERIC_EXAMPLES.md
+21-18Lines changed: 21 additions & 18 deletions
Original file line number
Diff line number
Diff line change
@@ -5,10 +5,10 @@ This document contains my solutions to the SQLZoo ['Numeric Examples (NSS Tutori
5
5
---
6
6
7
7
## Problem 1
8
-
The example shows the number who responded for:
8
+
The example shows the number who responded for:
9
9
* question 1
10
10
* at 'Edinburgh Napier University'
11
-
* studying '(8) Computer Science'
11
+
* studying '(8) Computer Science'
12
12
Show the the percentage who STRONGLY AGREE.
13
13
14
14
**My Solution:**
@@ -24,7 +24,7 @@ AND subject = '(8) Computer Science';
24
24
---
25
25
26
26
## Problem 2
27
-
Show the institution and subject where the score is at least 100 for question 15.
27
+
Show the institution and subject where the score is at least 100 for question 15.
28
28
29
29
**My Solution:**
30
30
@@ -38,7 +38,7 @@ AND score >= 100;
38
38
---
39
39
40
40
## Problem 3
41
-
Show the institution and score for Computer Science with score less than 50 for question Q15.
41
+
Show the institution and score where the score for '(8) Computer Science' is less than 50 for question 'Q15'.
42
42
43
43
**My Solution:**
44
44
@@ -53,7 +53,7 @@ AND score < 50;
53
53
---
54
54
55
55
## Problem 4
56
-
Show the subject and total number of students who responded to question 22 for Computer Science and Creative Arts and Design.
56
+
Show the subject and total number of students who responded to question 22 for each of the subjects '(8) Computer Science' and '(H) Creative Arts and Design'.
57
57
58
58
**My Solution:**
59
59
@@ -66,12 +66,12 @@ HAVING subject IN ('(8) Computer Science', '(H) Creative Arts and Design');
66
66
```
67
67
68
68
**My Notes:**
69
-
Use `SUM()` over the `response` column and `GROUP BY` subject to get totals.
69
+
Use `SUM()` over the response column, and `GROUP BY` subject to get totals.
70
70
71
71
---
72
72
73
73
## Problem 5
74
-
Show the subject and total number of students who strongly agreed to question 22 for Computer Science and Creative Arts and Design.
74
+
Show the subject and total number of students who A_STRONGLY_AGREE to question 22 for each of the subjects '(8) Computer Science' and '(H) Creative Arts and Design'.
75
75
76
76
**My Solution:**
77
77
@@ -84,37 +84,41 @@ HAVING subject IN ('(8) Computer Science', '(H) Creative Arts and Design');
84
84
```
85
85
86
86
**My Notes:**
87
-
Multiply percentage by response count, divide by 100, and sum the values.
87
+
The A_STRONGLY_AGREE column is a percentage. Multiply percentage by response count, divide by 100, and sum the values.
88
88
89
89
---
90
90
91
91
## Problem 6
92
-
Show the percentage of students who strongly agreed to question 22 for Computer Science and Creative Arts and Design, rounded to the nearest whole number.
92
+
Show the percentage of students who A_STRONGLY_AGREE to question 22 for the subject '(8) Computer Science' show the same figure for the subject '(H) Creative Arts and Design'.
93
+
Use the `ROUND` function to show the percentage without decimal places.
HAVING subject IN ('(8) Computer Science', '(H) Creative Arts and Design');
102
105
```
103
106
104
107
**My Notes:**
105
-
Calculate weighted average and round to zero decimal places.
108
+
Calculate the weighted average and round to zero decimal places.
106
109
107
110
---
108
111
109
112
## Problem 7
110
-
Show the average scores for question Q22 for each institution with 'Manchester' in the name, rounded to the nearest whole number.
113
+
Show the average scores for question 'Q22' for each institution that include 'Manchester' in the name.
114
+
The column score is a percentage - you must use the method outlined above to multiply the percentage by the response and divide by the total response. Give your answer rounded to the nearest whole number.
111
115
112
116
**My Solution:**
113
117
114
118
```sql
115
-
SELECT institution, ROUND(
116
-
SUM(score * response) /SUM(response),
117
-
0)
119
+
SELECT
120
+
institution,
121
+
ROUND(SUM(score * response) /SUM(response), 0)
118
122
FROM nss
119
123
WHERE institution LIKE'%Manchester%'
120
124
AND question ='Q22'
@@ -124,7 +128,7 @@ GROUP BY institution;
124
128
---
125
129
126
130
## Problem 8
127
-
Show the institution, total sample size, and number of computing students for Manchester institutions for Q01.
131
+
Show the institution, the total sample size and the number of computing students for institutions in Manchester for 'Q01'.
128
132
129
133
**My Solution:**
130
134
@@ -135,8 +139,7 @@ SELECT
135
139
SUM(
136
140
CASE WHEN subject ='(8) Computer Science' THEN sample
0 commit comments