how to find nth highest salary
Answer Posted / suprotim agarwal
CREATE TABLE #Employees (EmpID int, EmpName varchar(10),
Salary int)
INSERT #Employees SELECT 1,'Tim',345345
INSERT #Employees SELECT 2,'Jill',76845
INSERT #Employees SELECT 3,'Kathy',234545
INSERT #Employees SELECT 4,'Jack',74564
INSERT #Employees SELECT 5,'Harry',56756456
INSERT #Employees SELECT 6,'Arnol',75675
INSERT #Employees SELECT 7,'Dave',76566
INSERT #Employees SELECT 8,'Zinnade',58776
INSERT #Employees SELECT 9,'Iflar',345567
INSERT #Employees SELECT 10,'Jimmy',76766
Highest Salary Of an Employee
SELECT EmpName, Salary
from
(
SELECT EmpName, Salary, Row_Number() OVER(ORDER BY SALARY
DESC) AS 'Salaries'
FROM #Employees
) emp
WHERE Salaries = 1
2nd highest salary
SELECT EmpName, Salary
from
(
SELECT EmpName, Salary, Row_Number() OVER(ORDER BY SALARY
DESC) AS 'Salaries'
FROM #Employees
) emp
WHERE Salaries = 2
| Is This Answer Correct ? | 0 Yes | 1 No |
Post New Answer View All Answers
What will be the value of @@fetch_status if a row that was a part of the cursor resultset has been deleted from the database after the time the stored procedure that opened the cursor was executed?
What are approximate numeric data types in ms sql server?
What is a select query statement in ms sql server?
Why we use the openxml clause?
Explain following error properties?
State a few properties of relational databases?
Different types of keys in SQL?
How many joins in sql server?
What do you understand by coalesce in sql server?
What is a Join and explain its types?
How do we upgrade from SQL Server 6.5 to 7.0 and 7.0 to 2000?
What is history table in sql server?
What is 5nf in normalization form?
What happens if null values are involved in arithmetic operations?
What are constraints?