Alternative if interviewer ask to not to use windows functions: CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT BEGIN SET N = N-1; RETURN ( # Write your MySQL query statement below. select distinct salary from Employee order by salary desc limit 1 offset N ); END
man you are wonderful. You are the only I guy I have seen that writes FROM before SELECT, which is how it should be
Alternative if interviewer ask to not to use windows functions:
CREATE FUNCTION getNthHighestSalary(N INT) RETURNS INT
BEGIN
SET N = N-1;
RETURN (
# Write your MySQL query statement below.
select
distinct salary
from Employee
order by salary desc
limit 1 offset N
);
END
@devsagar
can you tell how it works fine with this test case??
| id | salary |
| -- | ------ |
| 1 | 100 |
| 2 | 100 |
can you explain why u write in code where rnk = n
n could be anything 1,2,3, and rnk is the name given to over(order by sal desc)