Friday, February 15, 2013

SQL Server MIN function

SQL Server MIN function

 SQL Server MIN function finds lowest/least element from  numeric values,  finds the lowest value in collating  Sequence for character columns. gets Minimum date from date column values


MIN(Sal) on Emp table


EMPNOENAMEJOBMGRHIREDATESALCOMMDEPTNO
7369SMITHCLERK790212/17/1980 12:00:00 AM800.00
20
7499ALLENSALESMAN76982/20/1981 12:00:00 AM1600.00300.0030
7521WARDSALESMAN76982/22/1981 12:00:00 AM1250.00500.0030
7566JONESMANAGER78394/2/1981 12:00:00 AM2975.00
20
7654MARTINSALESMAN76989/28/1981 12:00:00 AM1250.001400.0030
7698BLAKEMANAGER78395/1/1981 12:00:00 AM2850.00
30
7782CLARKMANAGER78396/9/1981 12:00:00 AM2450.00
10
7839KINGPRESIDENT
11/17/1981 12:00:00 AM5000.00
10
7844TURNERSALESMAN76989/8/1981 12:00:00 AM1500.000.0030
7900JAMESCLERK769812/3/1981 12:00:00 AM950.00
30
7902FORDANALYST756612/3/1981 12:00:00 AM3000.00
20
7934MILLERCLERK77821/23/1982 12:00:00 AM1300.00
10

Query:  Select Min salary from the Employees Table
     
             select Min(sal) from emp;
O/P:
         800.00

         select Min(sal) as "MinimumSalary"  from emp;

O/P:       
            "Minimum Salary"
             800.00

Query: Select Minimum salary from Dept No 10:

select Min(sal)  from emp where deptno=10;

O/P: 1300.00


Query: Get Minumum Salary from each Dept..

             select deptno,Min(sal) "Dept Minimum Salary" from emp group by deptno;

O/P :

deptno    Dept Minimum Salary
10    1300.00
20    800.00
30    950.00


Tags:SQL-Server MIN function, SQL Server MIN function, SQL Server Aggregate function, SQL Server 2012 MIN function,using MIN in T-SQL,using MIN in Select,using MIN in Having,MIN in T-SQL

No comments:

Post a Comment