Content navigation
1. Definitions
Max and Min return expr group of maxima and minima, acting on NUMBER, DATE, CHAR and VARCHAR2 data types. They actual input arguments and return values of the same data type, this value is the maximum or group, or is a minimum value. When applied to Date, Max returns the most recent date, Min returns the earliest date. NLS is set according to the database, to convert a string of digits represent its characters. When the Min function is applied to a set of strings, the words in alphabetical order to return the first occurrence of the word appearing last return Max.
2, Grammar
Max and Min function syntax is as follows:
Max( [DISTINCT | ALL] expr )
Min( [DISTINCT | ALL] expr )
This syntax can be broken down into the following form:
Max( DISTINCT expr );Min( DISTINCT expr );
Max( ALL expr );Min( ALL expr );
Max( expr );Min( expr );
The above-described expressions check value expr a set of rows and which returns the maximum, or the minimum value.
3, Code
/*
作者:AT阿宝哥
日期:2016年9月18日
愿景:参考官方资料,做最好的课程,成就更多职业人!
邮箱:[email protected]
CSDN:https://blog.csdn.net/goldentec
简书:https://www.jianshu.com/u/8a6075d7a2e0
说明:
注意:
*/
-------------------------------------------------------------------------------
--Sample1:NUMBER数据类型
SELECT MAX(sal),MIN(sal) FROM emp;
-------------------------------------------------------------------------------
--Sample12:VARCHAR2数据类型
SELECT MAX(ename),MIN(ename) FROM emp;
SELECT MAX(job),MIN(job) FROM emp;
-------------------------------------------------------------------------------
--Sample3:DATE数据类型
SELECT MAX(hiredate),MIN(hiredate) FROM emp;
-------------------------------------------------------------------------------