Complete the code to return NULL if the two values are equal.
SELECT NULLIF(5, [1]);
The NULLIF function returns NULL if both arguments are equal. Here, 5 equals 5, so the result is NULL.
Complete the code to return the first value when the two values are different.
SELECT NULLIF('apple', [1]);
NULLIF returns the first value if the two values are different. 'apple' and 'orange' are different, so it returns 'apple'.
Fix the error in the code to correctly use NULLIF with a column named score.
SELECT NULLIF(score, [1]) FROM results;To compare the column score to itself, use the column name without quotes. Using quotes treats it as a string literal.
Fill both blanks to return NULL if age equals 18, otherwise return age.
SELECT NULLIF([1], [2]) AS result FROM users;
NULLIF compares the first argument to the second. Using age and 18 (number) correctly returns NULL if age is 18.
Fill all three blanks to return status in uppercase if status equals 'active', else return status.
SELECT COALESCE(NULLIF([1], [2]), [3]) AS status_check FROM accounts;
NULLIF returns NULL if status equals 'active'. COALESCE then returns the uppercase status if NULLIF returns NULL.