Question:
minvalue.sql Select the Nth lowest value from a table
Answer:
select level, min('col_name') from my_table where level = '&n' connect by prior ('col_name') < 'col_name') group by level; Example: Given a table called emp with the following columns: -- id number -- name varchar2(20) -- sal number -- -- For the second lowest salary: -- select level, min(sal) from emp -- where level=2 -- connect by prior sal < sal -- group by level Source: CoolInterview.com
select max(sal)"nth min sal" from(select distinct sal from emp order by sal) where rownum<=&N; Source: CoolInterview.com
Answered by: shiva | Date: 4/23/2010
| Contact shiva
select max(sal)"nth min sal" from(select distinct sal from emp order by sal) where rownum<=&N; Source: CoolInterview.com
Answered by: shiva | Date: 4/23/2010
| Contact shiva
SELECT max(salary) FROM (SELECT employee_id , salary , dense_rank() over (order by salary) poradi FROM employees) WHERE poradi = n Source: CoolInterview.com
Answered by: Lenka | Date: 6/24/2010
| Contact Lenka
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|