Exercise · SQL & Querying
Predict, then run it
Predict the output
chili(entry, heat) = (a,9),(b,5),(c,1). Bucket into blazing/toasty/cool and display hottest-first (not alphabetical) with a rank-mapping CASE:
SELECT tier, n FROM (SELECT CASE WHEN heat >= 8 THEN 'blazing' WHEN heat >= 4 THEN 'toasty' ELSE 'cool' END AS tier, COUNT(*) AS n, MIN(CASE WHEN heat >= 8 THEN 1 WHEN heat >= 4 THEN 2 ELSE 3 END) AS rk FROM chili GROUP BY tier) ORDER BY rk;
Predict the exact output.