Tuesday, April 30, 2019

Second most Highest Salary SQl server

Find Second most Highest salary.

Emp Name  | Salary
a                 | 200000
b                |  50000
c               | 90000
d                 | 100000

Select name, max(Salary) as salary from employee WHERE salary < (Select Max(Salary) From Employee)

Find Third Higher Salary:

Select name, max(Salary) as salary from employee
WHERE salary <
(
Select max(Salary) as salary from employee WHERE salary < (Select Max(Salary) From Employee)
)

By DENSE Rank:
WITH T AS
(
     SELECT * FROM DENSE_RANK() OVER (ORDER BY Salary Desc) AS rank
From Employees
)
SELECT Name
FROM T
WHERE
rank = 2

By Top 1:

Select name, Salary FROM Employee
WHERE Salary < (Select Top 1 Salary From employee Order By Salary Desc)

No comments:

Post a Comment

Screen Record

 Windows Screen Record WindowsKey+ Alt + R Recording Starts.