Friday, June 25, 2010

How to find fifth highest salary

eg1:

select remaining_funds from election a where 4=(select count(distinct remaining_funds) from election b
where a.remaining_funds < b.remaining_funds)
eg2:
select top 1 salary from (select top 5 salary from tbl_Employee order by salary desc)


Top 5 salaries:
select distinct(remaining_funds) from election a where 4>=(select count(distinct remaining_funds) from election b
where a.remaining_funds < b.remaining_funds) order by remaining_funds desc

No comments: