Home » Developer & Programmer » Forms » n th maximum salary from emp table
n th maximum salary from emp table [message #82095] Tue, 22 April 2003 11:45 Go to next message
Rishi
Messages: 63
Registered: January 2001
Member
hi all!!
its very common interview question... n th maximum salary from emp table...plz send the query 4 it
Rishi
Re: n th maximum salary from emp table [message #82096 is a reply to message #82095] Tue, 22 April 2003 13:28 Go to previous messageGo to next message
Julie
Messages: 98
Registered: February 2002
Member
I don't know if this is the standard answer, because I just made it up, but to select the 9th highest salary:

SELECT min(salary)
FROM (SELECT salary FROM emp ORDER BY salary DESC)
where rownum < 10
Re: n th maximum salary from emp table [message #82100 is a reply to message #82095] Tue, 22 April 2003 22:19 Go to previous message
AM
Messages: 10
Registered: November 2001
Junior Member
Try This:-
select sal from emp a
where &count=(select count(distinct sal) from emp b
where a.sal<=b.sal)

Count is the nth position you want to see.

If you make : -
select sal from emp a
where &count<=(select count(distinct sal) from emp b
where a.sal<=b.sal)

Then you can find lowest to nth position.

You can also try more combinations to the same.
Previous Topic: EZSQL 2.10 - Paid version
Next Topic: Formatting data exported from forms6i to Microsoft Excel using DDE Package
Goto Forum:
  


Current Time: Fri Apr 26 09:14:17 CDT 2024