Tuesday, February 23, 2016

GREATEST

Hi all , hope you aware of MIN and MAX function in Oracle SQL. These functions are used as grouping function which can calculate the minimum or maximum value in a particular column. Since we normally group against a column. 
Requirement : Let us assume we have a table shown in the picture . Students and their marks against each subject as separate column. Now we have to find the maximum mark scored by a student across the subjects ( that is maximum value between English, Maths and Science for a student) as shown in the picture.  
Solution:  
SELECT student_name, GREATEST (english, maths, science)   FROM student;


GREATEST is a SQL function used to get max value between columns.