Cellwise · SQL track

Labels and buckets with CASE

Turn values into categories inside a query.

CASE works like IF in a spreadsheet. It checks conditions in order, and returns the value for the first one that’s true, or the ELSE value if none are.

Inside SUM, a CASE that gives 1 or 0 counts only the rows you care about, which lets one query count several things side by side.

What you’ll do

Start the lesson, free