query
-
Select *,sal From Emp X Where 5 = ( Select Count(Distinct Sal) From Emp Where sal >=X.sal )
-
Select *,sal From Emp X Where 5 = ( Select Count(Distinct Sal) From Emp Where sal >=X.sal )
Hi! In SQL 2005 you should use CTE and the new ranking functions; write
with EmpCTE ( EmpNo, ..., Sal, SalRank ) as ( select EmpNo, ..., Sal, dense_rank() over ( order by Sal desc ) ) select * from EmpCTE where SalRank=5;
Rainer Stropek cubido business solutions gmbh Email r.stropek@cubido.at Visit my blog at http://www.cubido.at/Blog/tabid/176/BlogID/4/Default.aspx -
SELECT TOP 1 * FROM (SELECT TOP 5 salary FROM employees ORDER BY salary DESC) AS EMP ORDER BY salary ASC
---------- Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peters