Conditional logic
SQL Conditional Logic Interview Questions
Conditional logic is how you decide a value row by row, using CASE WHEN in SQL. It is what turns a business rule into something a query can produce: sorting numbers into bands, labeling rows, or splitting one column into several.
What conditional logic questions ask you to do
Across the questions here, these are the shapes that come up:
- Sort a number into named bands such as high, mid and low
- Count only the rows that meet a condition
- Turn values from one column into several columns
- Flag a row using a rule that spans two columns
- Replace an empty value with something meaningful
Common mistakes with conditional logic
A CASE stops at the first branch that matches, so bands have to be written narrowest first. Put "over 100" before "over 500" and nothing is ever labeled high, because everything matches the first branch. A CASE with no ELSE is the other trap: every row that falls through comes back empty and then vanishes from any total built on it.
Questions to practice
- Price bandsSQL
Amazoneasy - Stock statusSQL
Amazoneasy - Surge share by citySQL
Lyfteasy - Cancellation rate by room typeSQL
Airbnbmedium - Completed versus other ordersSQL
Stripemedium - Completion rate by content typeSQL
Netflixmedium - Employee senioritySQL
Googlemedium - Net balance by accountSQL
Stripemedium - Open positions by userSQL
Robinhoodmedium - Share of plays cut shortPandas
Pandoramedium - Win rate by sales repSQLPremium
Salesforcemedium - Cross-border share by card tierSQL
Visahard
Questions last reviewed 19 October 2026.