thinQmaster Virtual testing partner Adaptive practice exams that find your weak spots and drill them. Every answer explained. From $69
Enroll

thinQmaster

Find your exam

Five questions free, before you decide.

Step 1 · choose a vendor

In one of our camps? Your practice exams come with the tuition — they are on your study page already.

Data & Analytics · Foundational

CASE Expression

SQL's conditional expression, which returns a value based on the first WHEN condition that is true.

Definition

Searched CASE evaluates Boolean conditions (CASE WHEN x > 10 THEN ...), while simple CASE compares one expression with values. If nothing matches and there is no ELSE, CASE returns NULL. It is used for bucketing, recoding and conditional aggregation.

Example

SUM(CASE WHEN Status = 'Returned' THEN 1 ELSE 0 END) AS Returns

Exam tip

CASE stops at the first true WHEN, so order the conditions from most to least specific.

Related terms