In Development: This textbook is currently
undergoing development and should not be used as an authoritative
source of... well, ANYTHING.
8 Conditional Expressions
8.1 Learning Objectives
By the end of this chapter, students will be able to:
- Write a searched
CASE WHENexpression to produce a conditional column in query output. - Write a simple
CASEexpression that compares a single value against a list of alternatives. - Apply
CASE WHENinside aggregate functions to compute conditional counts and sums in a single query. - Use
COALESCEto substitute a default value forNULLin query results. - Apply
NULLIFto returnNULLwhen two expressions are equal, preventing division-by-zero errors. - Distinguish between
COALESCE(returns first non-null) andNULLIF(returns null on equality) and select the appropriate function for a given scenario. - Combine
CASE WHENwithGROUP BYto create custom categorical groupings from continuous or multi-valued columns. - Evaluate whether a conditional expression problem is best solved with
CASE WHEN,COALESCE, orNULLIF.
Stub: CASE WHEN, NULLIF, and COALESCE as conditional tools.