0
0
PostgreSQLquery~10 mins

GREATEST and LEAST functions 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 find the greatest value among three numbers.

PostgreSQL
SELECT GREATEST([1]) AS max_value;
Drag options to blanks, or click blank then click option'
A5, 10, 3
B5 10 3
C'5', '10', '3'
D(5, 10, 3)
Attempts:
3 left
💡 Hint
Common Mistakes
Passing numbers without commas
Using quotes around numbers making them strings
Passing a tuple instead of separate arguments
2fill in blank
medium

Complete the code to find the least value among columns price1, price2, and price3 in the products table.

PostgreSQL
SELECT LEAST([1]) AS min_price FROM products;
Drag options to blanks, or click blank then click option'
Aprice1 price2 price3
Bprice1, price2, price3
C'price1', 'price2', 'price3'
D(price1, price2, price3)
Attempts:
3 left
💡 Hint
Common Mistakes
Omitting commas between column names
Putting column names in quotes
Using parentheses around the list as a single argument
3fill in blank
hard

Fix the error in the code to correctly find the greatest value between two columns colA and colB.

PostgreSQL
SELECT GREATEST([1]) AS max_val FROM data;
Drag options to blanks, or click blank then click option'
A(colA, colB)
BcolA colB
CcolA, colB
D'colA', 'colB'
Attempts:
3 left
💡 Hint
Common Mistakes
Missing commas between column names
Using quotes around column names
Passing columns as a tuple
4fill in blank
hard

Fill both blanks to find the least value between two columns and rename the output as lowest.

PostgreSQL
SELECT LEAST([1]) AS [2] FROM sales;
Drag options to blanks, or click blank then click option'
Acost, price
Bmin_value
Clowest
Dcost price
Attempts:
3 left
💡 Hint
Common Mistakes
Not separating columns with commas
Using invalid alias names or quotes around alias
Putting spaces instead of commas between columns
5fill in blank
hard

Fill all three blanks to select the greatest value between col1 and col2, rename it as max_col, and filter rows where the greatest value is greater than 100.

PostgreSQL
SELECT GREATEST([1]) AS [2] FROM records WHERE GREATEST([3]) > 100;
Drag options to blanks, or click blank then click option'
Acol1, col2
Bmax_col
Dcol1 col2
Attempts:
3 left
💡 Hint
Common Mistakes
Using spaces instead of commas between columns
Using different column lists in SELECT and WHERE
Using quotes around alias or columns