How To Find Nth Salary Of Employee
The question always asked during interview is how to find Nth salary of Employee
Employee_Salary
Example
# SELECT Top 1 Emp_Salary FROM (Select Top 3 Emp_Salary form Employee_Salary order by Emp_Salary desc) as EmpSalary order by Emp_Salary
/// output is 12000
Note:
# Let we consider a table Employee_Salary contains the columns Emp_Id,Emp_Name,Emp_Salary.
## Now we go through Nth Salary
* SELECT Top 1 Emp_Salary FROM (Select Top Nth Emp_Salary form Employee_Salary order by Emp_Salary desc) as EmpSalary order by Emp_Salary
Example
# SELECT Top 1 Emp_Salary FROM (Select Top 3 Emp_Salary form Employee_Salary order by Emp_Salary desc) as EmpSalary order by Emp_Salary
/// output is 12000
Note:
* Here Nth is any number of which you want to find out the salary.
* Here EmpSalary is an alias.
* Top Nth indicates the number (Ex. 1,2,3,4,5,......).
///////ouput is nth number of Emp_Salary
Dont Forget to comment and any query regarding sql database
ReplyDelete