Kodewick
Start learning →
Basic←→0 / 70

Letter grades

#056BasicCASE4 min

The teacher wants math scores as letters: 'A' for 90 and up, 'B' for 75 and up, 'C' for 60 and up, 'D' for the rest. From scores, pick the math rows (subject is 'math') with three columns: student_id, score and the letter.

The tables
students
idnameclassagecity
1Amy1A12Leeds
2Ben1A13York
3Cara1B12NULL
4Dan1B14Leeds
5Eva1A12Hull
6Finn1C13NULL
7Gus1C12York
7 rows
scores
idstudent_idsubjectscore
11math92
21art78
32math65
42art88
53math74
64math55
74art90
85math81
95artNULL
107math99
10 rows
query.sql
SELECT student_id, score,
  CASE
    -- your code here: three WHENs from high to low (90, 75, 60), then ELSE 'D'
  END
FROM scores
WHERE subject = 'math';
Ctrl + Enter runs too
Result

Run shows what your query gives. When it looks right, Submit.