A business user needs to calculate the average age of customers, but some age fields are NULL. Which function should be used to treat NULL as 0?
Trap 1: NULLIF
NULLIF returns NULL if two expressions are equal.
Trap 2: IFNULL
IFNULL is vendor-specific (MySQL).
Trap 3: ISNULL
ISNULL is vendor-specific (T-SQL) and less portable than COALESCE.
- A
NULLIF
Why it fails: NULLIF returns NULL if two expressions are equal.
- B
IFNULL
Why it fails: IFNULL is vendor-specific (MySQL).
- C
COALESCE
COALESCE is the standard SQL function for handling NULLs.
- D
ISNULL
Why it fails: ISNULL is vendor-specific (T-SQL) and less portable than COALESCE.