Introduction
These functions help you find the biggest or smallest value from a list of values quickly, like choosing the highest or lowest score.
GREATEST(value1, value2, ..., valueN) LEAST(value1, value2, ..., valueN)
SELECT GREATEST(10, 20, 15);
SELECT LEAST(10, 20, 15);
SELECT GREATEST('apple', 'banana', 'cherry');
SELECT LEAST('apple', 'banana', 'cherry');
CREATE TABLE scores ( student VARCHAR(20), test1 INT, test2 INT, test3 INT ); INSERT INTO scores VALUES ('Alice', 85, 90, 78), ('Bob', 70, 88, 95), ('Carol', 92, 85, 87); SELECT student, GREATEST(test1, test2, test3) AS highest_score, LEAST(test1, test2, test3) AS lowest_score FROM scores;
GREATEST function do in PostgreSQL?GREATEST function compares all given values and finds the largest one.LEAST returns the smallest, counting and averaging are different functions.SELECT GREATEST(7, 2, 9, 4) AS max_val, LEAST(7, 2, 9, 4) AS min_val;
SELECT GREATEST(4, 8, 'ten') AS max_value;
scores with columns math, science, and english. Which query correctly finds the highest and lowest score for each student?Pass the test and this pattern moves unknown