STEPS:
1. First create a table called employee
CREATE TABLE Employee
(
Emp_ID INT Identity,
Emp_name Varchar(100),
Emp_Sal Decimal (10,2)
)
2. Insert some column in employee table.
INSERT INTO Employee VALUES ('A',1000);
INSERT INTO Employee VALUES ('B',1200);
INSERT INTO Employee VALUES ('C',1100);
INSERT INTO Employee VALUES ('D',1300);
INSERT INTO Employee VALUES ('E',1400);
Highest Salary
SELECT max(Emp_Sal ) from employee
Minimum SalarySELECT min(Emp_Sal ) from employee
Nth Highest Salary
SELECT min(Emp_Sal) FROM Employee WHERE Emp_Sal IN
(SELECT DISTINCT TOP n Emp_Sal FROM Employee ORDER BY Emp_Sal DESC)
where n is number.If you want to calculate 2nd highest salary put 2 in place of n
3rd highest salary put 3 in place of n
SELECT min(Emp_Sal) FROM Employee WHERE Emp_Sal IN
(SELECT DISTINCT TOP 2 Emp_Sal FROM Employee ORDER BY Emp_Sal DESC)
1. First create a table called employee
CREATE TABLE Employee
(
Emp_ID INT Identity,
Emp_name Varchar(100),
Emp_Sal Decimal (10,2)
)
2. Insert some column in employee table.
INSERT INTO Employee VALUES ('A',1000);
INSERT INTO Employee VALUES ('B',1200);
INSERT INTO Employee VALUES ('C',1100);
INSERT INTO Employee VALUES ('D',1300);
INSERT INTO Employee VALUES ('E',1400);
Highest Salary
SELECT max(Emp_Sal ) from employee
Minimum SalarySELECT min(Emp_Sal ) from employee
Nth Highest Salary
SELECT min(Emp_Sal) FROM Employee WHERE Emp_Sal IN
(SELECT DISTINCT TOP n Emp_Sal FROM Employee ORDER BY Emp_Sal DESC)
where n is number.If you want to calculate 2nd highest salary put 2 in place of n
3rd highest salary put 3 in place of n
SELECT min(Emp_Sal) FROM Employee WHERE Emp_Sal IN
(SELECT DISTINCT TOP 2 Emp_Sal FROM Employee ORDER BY Emp_Sal DESC)
How to get 'nth' highest salary of employee ?
Reviewed by kamal kumar das
on
January 20, 2012
Rating:
No comments: