Questions: COALESCE and NULLIF: NULL Handling Functions

5 questions to test your understanding

Score: 0 / 5
Question 1 Multiple Choice

A query calculates revenue per unit with the expression `revenue / units_sold`. When units_sold is 0, the query crashes. Which expression fixes this while preserving NULL to signal the undefined result?

ACASE WHEN units_sold = 0 THEN 0 ELSE revenue / units_sold END
Brevenue / NULLIF(units_sold, 0)
CCOALESCE(revenue / units_sold, 0)
DISNULL(units_sold, 1)
Question 2 Multiple Choice

A customer table has three phone columns: mobile_phone, home_phone, work_phone. Many customers have only one or two. You want a single 'best contact number' column returning whichever is available, or 'No contact' if all are NULL. Which expression is correct?

AISNULL(mobile_phone, home_phone)
BCOALESCE(mobile_phone, home_phone, work_phone, 'No contact')
CNULLIF(mobile_phone, home_phone)
DCASE WHEN mobile_phone IS NOT NULL THEN mobile_phone WHEN home_phone IS NOT NULL THEN home_phone ELSE work_phone END
Question 3 True / False

COALESCE(a, b) and NULLIF(a, b) are inverses: COALESCE handles the case where a IS NULL, and NULLIF handles the case where a IS NOT NULL.

TTrue
FFalse
Question 4 True / False

COALESCE can accept more than two arguments and evaluates them in order, returning the first non-NULL value found.

TTrue
FFalse
Question 5 Short Answer

Explain how COALESCE and NULLIF work together in data cleaning pipelines, giving a concrete example.

Think about your answer, then reveal below.