Nivio Technologies Interview Question
Testing / Quality Assurancesalmost right.
you didn't consider the situation that many employees may have the salary at the fourth highest.
select name,salary
from employee
where sal in (SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP 4 salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary DESC)
Should it not be like this
select name,salary
from employee
where sal in (SELECT TOP 1 salary
FROM (
SELECT DISTINCT TOP 4 salary
FROM employee
ORDER BY salary DESC) a
ORDER BY salary ASC)
select name, salary
from employee t
where (select count(1) from employee t1 where t1.salary > t.salary) = 3;
hi there,
although your query is little heavy interms of performance, it yields correct results. Could you explain me your query when you gotta min..
If you are being interviewd by a top company, they expect u to answer it without using any keywords that commercial db's have.. i would go with the version that was answered above
####
select name, salary
from employee t
where (select count(1) from employee t1 where t1.salary > t.salary) = 3; ####
in mysql it can be done in simple way
it will give 4th salary, if you want 6th salary then replace 3 by 5
- kaustubh deshmukh September 18, 2012