Friday, February 15, 2013

SQL Server MAX function

SQL Server MAX function

 SQL Server Max function finds highest element from  numeric values,  finds the highest value in collating  Sequence for character columns. gets Maximum date from date column


Max(Sal) on Emp table


EMPNOENAMEJOBMGRHIREDATESALCOMMDEPTNO
7369SMITHCLERK790212/17/1980 12:00:00 AM800.0020
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.0020
7654MARTINSALESMAN76989/28/1981 12:00:00 AM1250.001400.0030
7698BLAKEMANAGER78395/1/1981 12:00:00 AM2850.0030
7782CLARKMANAGER78396/9/1981 12:00:00 AM2450.0010
7839KINGPRESIDENT11/17/1981 12:00:00 AM5000.0010
7844TURNERSALESMAN76989/8/1981 12:00:00 AM1500.000.0030
7900JAMESCLERK769812/3/1981 12:00:00 AM950.0030
7902FORDANALYST756612/3/1981 12:00:00 AM3000.0020
7934MILLERCLERK77821/23/1982 12:00:00 AM1300.0010

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

         select Max(sal) as "Maximum Salary"  from emp;

O/P:       
            "Maximum Salary"
             5000.00

Query: Select Maximum salary from Dept No 10:

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

O/P: 5000.00


Query: Get Maximum Salary from each Dept..

             select deptno,Max(sal) "Dept Maximum Salary" from emp group by deptno;

O/P :

deptno    Dept Maximum Salary
10    5000.00
20    3000.00
30    2850.00


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

No comments:

Post a Comment