Friday, May 3, 2013

ORACLE MIN FUNCTION


ORACLE MIN FUNCTION

                                 MIN function finds MINIMUM value in the column, ignores null values.

SYNTAX: MIN(expr)

MINIMUM SALARY IN THE COMPANY.
----------------------------------------------------
SQL> select min(salary) from employees;

min(SALARY)
-----------
      24000
Get MINIMUM SALARY DRAWN FROM EACH DEPT.
------------------------------------------------------------------------
SQL> select department_ID,min(Salary) from employees
  2  group by department_ID;

DEPARTMENT_ID min(SALARY)
------------- -----------
          100       12008
           30       11000
                     7000
           90       24000
           20       13000
           70       10000
          110       12008
           50       11808
           80       14000
           40        6500
           60        9000
           10        4400

12 rows selected.

Note: Group by department and then find min(salary)

GET min SALARY DRAWN ON EACH JOB CATEGORY
---------------------------------------------------------------------------
SQL> select job_ID,min(SALARY) from employees
  2  group by job_id;

JOB_ID     min(SALARY)
---------- -----------
IT_PROG           9000
AC_MGR           12008
AC_ACCOUNT        8300
ST_MAN           11808
PU_MAN           11000
AD_ASST           4400
AD_VP            17000
SH_CLERK          4200
FI_ACCOUNT        9000
FI_MGR           12008
PU_CLERK          3100
SA_MAN           14000
MK_MAN           13000
PR_REP           10000
AD_PRES          24000
SA_REP           11500
MK_REP            6000
ST_CLERK          5184
HR_REP            6500

19 rows selected.
Note: Group by Job category and then find min(salary)

GET SECOND HIGHEST SALARY
---------------------------------------------------
SQL> select min(salary) from employees where salary > (select min(salary) from employees);

min(SALARY)
-----------
      17000
Note: First find min salary then in the remaining values find again min salary(second minimum).

1 comment:

  1. Good illustration of MIN Function.

    More on the same can be learnt at

    http://techhoney.com/oracle/function/sql-min/

    also complete Oracle PL/SQL, Oracle APPS Framework and HTML can be learnt at

    http://techhoney.com

    ReplyDelete