-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStudent Grades
More file actions
62 lines (43 loc) · 1.09 KB
/
Copy pathStudent Grades
File metadata and controls
62 lines (43 loc) · 1.09 KB
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
Student Grades
Write a query to print the ID and StudentGrade for each record in the STUDENT table. Sort the output by student ID, ascending, and use the following format.
Student STUDENT.ID has grade: StudentGrade
If Score < 20, StudentGrade = F
If 20 ≤ Score < 40, StudentGrade = D
If 40 ≤ Score < 60, StudentGrade = C
If 60 ≤ Score < 80, StudentGrade = B
If Score ≥ 80, StudentGrade = A
Schema
STUDENT
Name Type Description
ID Integer primary key
SCORE Integer
Sample Data Tables
Sample Input
STUDENT
ID SCORE
1 20
2 50
3 50
4 68
5 95
Sample Output
Student 1 has grade: D
Student 2 has grade: C
Student 3 has grade: C
Student 4 has grade: B
Student 5 has grade: A
Explanation
The student with ID 1 has a SCORE of 20 and the grade D.
50 translates to C
68 translates to B
95 translates to A
//CODE
SELECT CONCAT('Student ', STUDENT.ID, ' has grade: ',
CASE
WHEN score < 20 THEN 'F'
WHEN score < 40 AND score >= 20 THEN 'D'
WHEN score < 60 AND score >= 40 THEN 'C'
WHEN score < 80 AND score >= 60 THEN 'B'
ELSE 'A'
END)
FROM student;