Добавить
Уведомления

6 Way to find out 2nd highest salary of employee | Coding Era

How to find out 2nd highest salary of employee? SQL Interview Query. This is a very common SQL Server Interview Question. There are several ways of finding the 2nd highest salary. How to find 2nd highest salary in SQL Server using a Sub-Query How to find 2nd highest salary in SQL Server using a CTE --Method 1 Select Distinct Salary From EmployeeSalary E1 Where(Select Count(Distinct Salary) From EmployeeSalary E2 Where E1.Salary <=E2.Salary)=2 --Method 2 Select Top 1 * From(Select Distinct Top 2 Salary From EmployeeSalary Order By Salary Desc) X Order By Salary --Mothod 3 Select Max(Salary) As Salary From EmployeeSalary Where Salary < (Select Max(Salary) From EmployeeSalary) --Method 4 Select Max(Salary) as Salary From EmployeeSalary Where Salary Not In(Select Max(Salary) From EmployeeSalary) --Method 5 Select Min(Salary) As Salary From(Select Distinct Top 2 Salary From EmployeeSalary Order By Salary Desc)X --Method 6 With Result As(Select Salary,DENSE_RANK() Over (Order By Salary Desc) As DensRank From EmployeeSalary) Select Top 1 Salary From Result Where DensRank=2 #codingera #sqlserver #sql #sqlinterview

12+
17 просмотров
2 года назад
12+
17 просмотров
2 года назад

How to find out 2nd highest salary of employee? SQL Interview Query. This is a very common SQL Server Interview Question. There are several ways of finding the 2nd highest salary. How to find 2nd highest salary in SQL Server using a Sub-Query How to find 2nd highest salary in SQL Server using a CTE --Method 1 Select Distinct Salary From EmployeeSalary E1 Where(Select Count(Distinct Salary) From EmployeeSalary E2 Where E1.Salary <=E2.Salary)=2 --Method 2 Select Top 1 * From(Select Distinct Top 2 Salary From EmployeeSalary Order By Salary Desc) X Order By Salary --Mothod 3 Select Max(Salary) As Salary From EmployeeSalary Where Salary < (Select Max(Salary) From EmployeeSalary) --Method 4 Select Max(Salary) as Salary From EmployeeSalary Where Salary Not In(Select Max(Salary) From EmployeeSalary) --Method 5 Select Min(Salary) As Salary From(Select Distinct Top 2 Salary From EmployeeSalary Order By Salary Desc)X --Method 6 With Result As(Select Salary,DENSE_RANK() Over (Order By Salary Desc) As DensRank From EmployeeSalary) Select Top 1 Salary From Result Where DensRank=2 #codingera #sqlserver #sql #sqlinterview

, чтобы оставлять комментарии