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
EMPNO | ENAME | JOB | MGR | HIREDATE | SAL | COMM | DEPTNO |
7369 | SMITH | CLERK | 7902 | 12/17/1980 12:00:00 AM | 800.00 | 20 | |
7499 | ALLEN | SALESMAN | 7698 | 2/20/1981 12:00:00 AM | 1600.00 | 300.00 | 30 |
7521 | WARD | SALESMAN | 7698 | 2/22/1981 12:00:00 AM | 1250.00 | 500.00 | 30 |
7566 | JONES | MANAGER | 7839 | 4/2/1981 12:00:00 AM | 2975.00 | 20 | |
7654 | MARTIN | SALESMAN | 7698 | 9/28/1981 12:00:00 AM | 1250.00 | 1400.00 | 30 |
7698 | BLAKE | MANAGER | 7839 | 5/1/1981 12:00:00 AM | 2850.00 | 30 | |
7782 | CLARK | MANAGER | 7839 | 6/9/1981 12:00:00 AM | 2450.00 | 10 | |
7839 | KING | PRESIDENT | 11/17/1981 12:00:00 AM | 5000.00 | 10 | ||
7844 | TURNER | SALESMAN | 7698 | 9/8/1981 12:00:00 AM | 1500.00 | 0.00 | 30 |
7900 | JAMES | CLERK | 7698 | 12/3/1981 12:00:00 AM | 950.00 | 30 | |
7902 | FORD | ANALYST | 7566 | 12/3/1981 12:00:00 AM | 3000.00 | 20 | |
7934 | MILLER | CLERK | 7782 | 1/23/1982 12:00:00 AM | 1300.00 | 10 |
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