BCG Interview Question | Salary
Question
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
It will take less than 1 minute to register for lifetime. Bonus Tip - We don't send OTP to your email id Make Sure to use your own email id for free books and giveaways
Answers ( 3 )
select * from (select id, name ,salary, dense_rank() over (order by salary desc) as s from Employee) as e
where e.s=10;
/*Using Common Table Expression*/ /* n=10 */
WITH Result as (Select Salary, Dense_Rank OVER (ORDER BY salary desc) as Dense_Rank from Employees)
SELECT salary
from Result
WHERE Dense_Rank =n;
/*Using LIMIT and OFFSET*/
Select *from Employees
Where Salary =(Select Distinct(Salary) from Employees Order by salary LIMIT n-1,1);
Select * from (
select ename,sal,dense_rank() OVER(order by sal desc)r from employee)
where r = 10
Explanation:
we will use the window function dense_rank() to rank according to descending
salaries and filter the rows which are getting a rank of 10