Examples Using GREATEST Function
Example 1: Let’s Say We Have a Table Called “Students” with the Following Data
We can create the Students table using the following code which defines the table structure with columns such as Stu_name, hindi, English and maths as Columns.
Query:
CREATE TABLE students (
Stu_name VARCHAR(50),
hindi INT,
english INT,
maths INT
);
INSERT INTO students (Stu_name, hindi, english, maths) VALUES
('John', 85, 90, 95),
('Alice', 78, 92, 88),
('Bob', 92, 85, 90),
('Emma', 80, 88, 92),
('Michael', 95, 82, 89);
Output:
Suppose we have to find the maximum mark for each student. we have to find the maximum mark for each student using the following query.
Query:
SELECT Stu_name,
GREATEST(hindi, english, maths) AS max_mark
FROM students;
Output:
Explanation: We can observe that the desired output is obtained.
How to Find the Maximum of Multiple Columns in PL/SQL?
In PL/SQL finding the maximum value of multiple columns is a common requirement for maintaining the database. This operation is important for various applications, ranging from financial analysis to data reporting. In this article, we will learn about How to find the maximum of multiple columns in PL/SQL with the help of two different methods to resolve problems by various examples and so on.