Declare @N Int =2 Select EmployeeSalary From ( Select Dense_Rank() Over (Order By EmployeeSalary) SNo, EmployeeSalary From TblEmployee) temp Where SNo =@N
Thanks for all the knowledge that you have shared and sharing with youtube family. Your videos are helpful for 1000s of people I am sure. I was looking for sql interview question's part 2,3 which you have mentioned in part 1 But I couldn't see link for that. Could you please share with us?
Instead of row_number we can use dense_rank , bcoz if the table has duplicate 2nd highest salary and we nned to show both then it is not possible by row_number()
Just make sure you are accessing membership videos from same google account from where you have made the purchase or you can contact youtube help center if you do not get the access.
Rank is simple , LIMIT will more simple ,but these are TSQL. Will not work for other DB. In todays date with EF and Code first ANSI SQL has become more important. Thanks.
the problem for me is that I don't want to get a job, because then I have to go to work... So I prefer to go unprepared to the interview, and then blame the company for xenofobia. High 5 !
CREATE FUNCTION getNthHighestSalary(@N INT) RETURNS INT AS BEGIN RETURN ( select distinct salary from Employee order by salary desc OFFSET @N-1 ROWS FETCH NEXT 1 ROWS ONLY ); END
The video demonstrates well the idea but probably is not going to work if there are duplicated salaries in the table. To solve this group by the salary in the sub query. However using rank will be a better solution selecting the nth rank as the nth top salary. In places where top or rank is not available an insert into temp table with autooncrement first column and sequential select the nth row from it will do too.