0
0
PostgreSQLquery~10 mins

NULLIF function behavior in PostgreSQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to return NULL if the two values are equal.

PostgreSQL
SELECT NULLIF(5, [1]);
Drag options to blanks, or click blank then click option'
A3
B7
C5
D10
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing a value different from 5 will return the first value instead of NULL.
2fill in blank
medium

Complete the code to return the first value when the two values are different.

PostgreSQL
SELECT NULLIF('apple', [1]);
Drag options to blanks, or click blank then click option'
A'orange'
B'apple'
C'apple '
D'APPLE'
Attempts:
3 left
💡 Hint
Common Mistakes
Choosing the same string will return NULL instead of the first value.
3fill in blank
hard

Fix the error in the code to correctly use NULLIF with a column named score.

PostgreSQL
SELECT NULLIF(score, [1]) FROM results;
Drag options to blanks, or click blank then click option'
Ascore
B'score'
CNULL
D0
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around column names causes the function to compare to a string, not the column value.
4fill in blank
hard

Fill both blanks to return NULL if age equals 18, otherwise return age.

PostgreSQL
SELECT NULLIF([1], [2]) AS result FROM users;
Drag options to blanks, or click blank then click option'
Aage
B18
C'18'
Duser_age
Attempts:
3 left
💡 Hint
Common Mistakes
Using quotes around 18 makes it a string, which may not match the numeric column.
5fill in blank
hard

Fill all three blanks to return status in uppercase if status equals 'active', else return status.

PostgreSQL
SELECT COALESCE(NULLIF([1], [2]), [3]) AS status_check FROM accounts;
Drag options to blanks, or click blank then click option'
Astatus
B'active'
CUPPER(status)
DLOWER(status)
Attempts:
3 left
💡 Hint
Common Mistakes
Using LOWER instead of UPPER changes the output case incorrectly.
Not quoting 'active' treats it as a column, causing errors.