.NET and SQL Server interview questions - Can you get second highest salary from the table?
Shivprasad Koirala
create table Employees (Name varchar(20),Salary numeric(18,2) )Insert into Employees(Name,Salary)values('D',3000);WITH T AS ( SELECT *,DENSE_RANK() OVER (ORDER BY Salary Desc) AS Rnk FROM Employees ) SELECT Name FROM T WHERE Rnk=2;
Answer: Let's us assume that we have the following table of Employee.
SELECT Emp_Name,Emp_SalaryFROM Employee e1WHERE2 = (SELECT COUNT(DISTINCT (e2.Emp_Salary))FROM Employee e2 WHERE e2.Emp_Salary >= e1.Emp_Salary)
Please click here to see more .NET and SQL Server interview questions