Bucket magnitudes into bands
IntermediateCASEEarthquakes (USGS, Oct 2026)
Label each event: below 4.0 is minor, 4.0–4.9 is light, 5.0–5.9 is moderate, 6.0+ is strong. Return each band and its count.
Solution
SELECT CASE
WHEN mag < 4 THEN 'minor'
WHEN mag < 5 THEN 'light'
WHEN mag < 6 THEN 'moderate'
ELSE 'strong'
END AS band,
COUNT(*) AS n
FROM quakes
GROUP BY band;Expected output:
Hint
CASE WHEN checks conditions top to bottom and returns the first match.
Same question in Excel / Google Sheets
Helper column =IFS(F2<4,"minor",F2<5,"light",F2<6,"moderate",TRUE,"strong"), then pivot.
Download the CSV from the datasets page. Column letters assume the CSV opens with its header in row 1.
Tip: Ctrl+Enter (⌘+Enter on Mac) checks your answer. Everything runs in your browser; nothing you type is sent anywhere.