0
0
PostgreSQLquery~10 mins

IF-ELSIF-ELSE control flow 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 'Positive' if the number is greater than zero.

PostgreSQL
SELECT CASE WHEN number [1] 0 THEN 'Positive' ELSE 'Non-positive' END AS result FROM numbers;
Drag options to blanks, or click blank then click option'
A>
B<
C=
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' will check for numbers less than zero, which is incorrect here.
Using '=' will only check for numbers equal to zero.
2fill in blank
medium

Complete the code to return 'Negative' if the number is less than zero.

PostgreSQL
SELECT CASE WHEN number [1] 0 THEN 'Negative' ELSE 'Non-negative' END AS result FROM numbers;
Drag options to blanks, or click blank then click option'
A<
B>=
C=
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>=' will check for numbers greater or equal to zero, which is incorrect here.
Using '=' will only check for numbers equal to zero.
3fill in blank
hard

Fix the error in the CASE statement to handle zero correctly.

PostgreSQL
SELECT CASE WHEN number > 0 THEN 'Positive' WHEN number [1] 0 THEN 'Zero' ELSE 'Negative' END AS result FROM numbers;
Drag options to blanks, or click blank then click option'
A>
B<
C<>
D=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '>' or '<' will not correctly identify zero.
Using '<>' means 'not equal', which is incorrect here.
4fill in blank
hard

Fill both blanks to complete the CASE statement that labels numbers as 'Positive', 'Zero', or 'Negative'.

PostgreSQL
SELECT CASE WHEN number [1] 0 THEN 'Positive' WHEN number [2] 0 THEN 'Zero' ELSE 'Negative' END AS result FROM numbers;
Drag options to blanks, or click blank then click option'
A>
B<
C=
D<=
Attempts:
3 left
💡 Hint
Common Mistakes
Using '<' instead of '>' for the first condition.
Using '<>' instead of '=' for the second condition.
5fill in blank
hard

Fill all three blanks to create a CASE statement that returns 'Positive', 'Zero', or 'Negative' based on the number.

PostgreSQL
SELECT CASE WHEN number [1] 0 THEN 'Positive' WHEN number [2] 0 THEN 'Zero' ELSE [3] END AS result FROM numbers;
Drag options to blanks, or click blank then click option'
A>
B=
C'Zero'
D'Negative'
Attempts:
3 left
💡 Hint
Common Mistakes
Putting 'Zero' in ELSE instead of the correct label.
Using wrong comparison operators for the conditions.