Definition:
The Oracle PL/SQL MIN function is used to get the minimum value of a column. Like the MAX function, the MIN function also shows both aggregate and analytic behavior.
Example Syntax
MIN(expression) OVER (analytic clause)
Example Usage
Aggregate: The below SQL retrieves the minimum salary in each job category from EMPLOYEE table.
SELECT JOB_ID, MIN(SALARY)
FROM EMPLOYEE
GROUP_BY JOB_ID
Analytic: The below SQL displays the most experienced employee in each job category.
SELECT ENAME, JOB_ID, HIRE_DATE
FROM
(
SELECT ENAME, JOB_ID, HIRE_DATE, MIN(HIRE_DATE) OVER (PARTITION BY JOB_ID) MIN_HIREDATE
FROM EMPLOYEE
)
WHERE TRUNC(HIRE_DATE)=TRUNC(MIN_HIREDATE)
Related Links:
Related Code Snippets: