Skip to content

Commit 0a288f2

Browse files
authored
Update 8+_NUMERIC_EXAMPLES.md
1 parent d1d9b38 commit 0a288f2

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

sqlzoo/8+_NUMERIC_EXAMPLES.md

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@ This document contains my solutions to the SQLZoo ['Numeric Examples (NSS Tutori
55
---
66

77
## Problem 1
8-
The example shows the number who responded for:
8+
The example shows the number who responded for:
99
* question 1
1010
* at 'Edinburgh Napier University'
11-
* studying '(8) Computer Science'
11+
* studying '(8) Computer Science'
1212
Show the the percentage who STRONGLY AGREE.
1313

1414
**My Solution:**
@@ -24,7 +24,7 @@ AND subject = '(8) Computer Science';
2424
---
2525

2626
## 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.
2828

2929
**My Solution:**
3030

@@ -38,7 +38,7 @@ AND score >= 100;
3838
---
3939

4040
## 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'.
4242

4343
**My Solution:**
4444

@@ -53,7 +53,7 @@ AND score < 50;
5353
---
5454

5555
## 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'.
5757

5858
**My Solution:**
5959

@@ -66,12 +66,12 @@ HAVING subject IN ('(8) Computer Science', '(H) Creative Arts and Design');
6666
```
6767

6868
**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.
7070

7171
---
7272

7373
## 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'.
7575

7676
**My Solution:**
7777

@@ -84,37 +84,41 @@ HAVING subject IN ('(8) Computer Science', '(H) Creative Arts and Design');
8484
```
8585

8686
**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.
8888

8989
---
9090

9191
## 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.
9394

9495
**My Solution:**
9596

9697
```sql
97-
SELECT subject, ROUND(SUM(response*A_STRONGLY_AGREE)/SUM(response),0)
98+
SELECT
99+
subject,
100+
ROUND(SUM(response*A_STRONGLY_AGREE) / SUM(response), 0)
98101
FROM nss
99102
WHERE question = 'Q22'
100103
GROUP BY subject
101104
HAVING subject IN ('(8) Computer Science', '(H) Creative Arts and Design');
102105
```
103106

104107
**My Notes:**
105-
Calculate weighted average and round to zero decimal places.
108+
Calculate the weighted average and round to zero decimal places.
106109

107110
---
108111

109112
## 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.
111115

112116
**My Solution:**
113117

114118
```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)
118122
FROM nss
119123
WHERE institution LIKE '%Manchester%'
120124
AND question = 'Q22'
@@ -124,7 +128,7 @@ GROUP BY institution;
124128
---
125129

126130
## 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'.
128132

129133
**My Solution:**
130134

@@ -135,8 +139,7 @@ SELECT
135139
SUM(
136140
CASE WHEN subject = '(8) Computer Science' THEN sample
137141
ELSE 0
138-
END
139-
) AS comp
142+
END) AS comp
140143
FROM nss
141144
WHERE question = 'Q01'
142145
AND institution LIKE '%Manchester%'

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy