All quizzesEasy
CASE, COALESCE & Functions
Preview — 3 of 10 questions
What does the following query return for a row where score = 45?
javascript
SELECT
name,
CASE
WHEN score >= 90 THEN 'A'
WHEN score >= 75 THEN 'B'
WHEN score >= 60 THEN 'C'
ELSE 'F'
END AS grade
FROM students;A'F'
B'C'
C'B'
DNULL
What does COALESCE(NULL, NULL, 'default', 'other') return?
ANULL
B'default'
C'other'
DAn error
Which of the following correctly avoids a division-by-zero error?
javascript
-- Safe division pattern
SELECT
product,
NULLIF(quantity_sold, 0) AS safe_divisor,
revenue / NULLIF(quantity_sold, 0) AS avg_price
FROM sales;ASELECT total / count FROM orders
BSELECT total / NULLIF(count, 0) FROM orders
CSELECT COALESCE(total / count, 0) FROM orders
DSELECT ISNULL(total / count, 0) FROM orders
Sign up free to play
Answer all 10 questions (7 more), see explanations for every answer, and track your score.