[algogeeks] Query to find the Nth highest salary in employee table

2011-08-06 Thread Reynald
Could anyone please explain me how this query selects the employee
with nth highest salary?

select last_name, salary from employees e1
where n = (select count(distinct(salary)) from employees e2
where e2.salary = e1.salary);

-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.



Re: [algogeeks] Query to find the Nth highest salary in employee table

2011-08-06 Thread coder dumca
select top 1 salary from(select top 6   salary from employee
order by salary desc)asc

On Sat, Aug 6, 2011 at 6:40 PM, Reynald reynaldsus...@gmail.com wrote:

 Could anyone please explain me how this query selects the employee
 with nth highest salary?

 select last_name, salary from employees e1
 where n = (select count(distinct(salary)) from employees e2
 where e2.salary = e1.salary);

 --
 You received this message because you are subscribed to the Google Groups
 Algorithm Geeks group.
 To post to this group, send email to algogeeks@googlegroups.com.
 To unsubscribe from this group, send email to
 algogeeks+unsubscr...@googlegroups.com.
 For more options, visit this group at
 http://groups.google.com/group/algogeeks?hl=en.



-- 
You received this message because you are subscribed to the Google Groups 
Algorithm Geeks group.
To post to this group, send email to algogeeks@googlegroups.com.
To unsubscribe from this group, send email to 
algogeeks+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/algogeeks?hl=en.