This works only if we have a unique salary... The best way to solve this kind of problem is to always use the dense_rank advance window function sql query logic.
SELECT salary FROM Employee ORDER BY Salary DESC LIMIT (Nth,1)
We can write select distinct (salary) from Employee order by salary desc limit 2,1
WITH CTE AS ( SELECT *, DENSE RANK() OVER ( ORDER BY salary DESC) as Rank FROM employee ) SELECT * FROM CTE WHERE Rank = N;
With cte as (Select *, Dense_rank() over(order by salary desc) as rank_) Select eid, salary From cte Rank_ = N
Select salary from employees Order by salary Desc Offset 2, limit 1;
Select * from emp order by salary desc limit 1 offset n
Select E1.salary from employees E1 where N-1 in (select count(distinct E2.salary) from employees E2 where E1.salary < E2.salary); In this question the N value will be 3.
Using MS server we write using derived table concept, Select top1 A.sal from (Select top 3 sal from employee order by sal desc)as A order by A.sal asc
Select salary from employee order by salary desc limit 1 offset 2;
SELECT Salary FROM ( SELECT Salary, DENSE_RANK() OVER (ORDER BY Salary DESC) AS rank FROM Employees ) ranking_salaries WHERE rank = 3;
Use limit 2 , offset 1 at last
Standard leetcode question
I don’t find 2nd session , post both question and answers so that helps viewers and you too to gain subscribers 👍
why no one talking about Window function Nthvalue? Select NTH_Value(salary,3) over(Order by Salary DESC) as 3rd_highiest from Employees. Any thoughts?
Ye MySQL ke liye theek hai. Oracle ke liye dense rank use krna pdega.
Select DISTINCT(salary) from Employees ORDER BY salary DESC LIMIT 2,1
We can also use Inline Subquery for this SELECT SALARY FROM (SELECT ROWNUM AS SRNO,SALARY FROM(SELECT DISTINCT SALARY FROM Employees) ORDER BY SALARY DESC)) WHERE SRNO IN (3);
Select eid, name, deptid, salary, age from employees order by salary desc limit 1 offset 2;
@Priya_devipalla