Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

Write sql a query to display the result 3rd maximum salary.

user-image
Question ajoutée par neha m
Date de publication: 2016/08/31
Nivya P J
par Nivya P J , Software Engineer , Essel SWolutions Pvt Ltd

SELECT TOP1 salary FROM  (SELECT TOP3 salary FROM Table_Name ORDER BY salary DESC) AS Q ORDER BY salary ASC

Utilisateur supprimé
par Utilisateur supprimé

select top 1 salary from

(select distinct top 3 salary form table_name

order by salary )

result

order by salary desc

Sayed Elshayeb
par Sayed Elshayeb , senior analyst programmer , EPL House

SELECT*FROM(SELECT ROW_NUMBER()OVER(ORDERBYkeyASC)AS rownumber, <columns> FROM <tablename> )AS foo WHERE rownumber = 3

Utilisateur supprimé
par Utilisateur supprimé

As I understood your question you can do it by using analytical functions, as example:

select n.* from(select  p.id, p.salary, rank() over (order by p.salary desc) as cn from(select 1 as id,1000 as salary union select 2,1500 union select 3,2500 union select 4,1200) as p)n where n.cn=3

Sarah Dwekat
par Sarah Dwekat , Database System Developer , Integrated Technology Group (ITG)

SELECT TOP1 Sal 

FROM ( SELECT DISTINCT TOP3 Sal

            FROM Salary

           ORDER BY Sal DESC ) AS ThirdSal ORDER BY Sal

More Questions Like This