TOP-N ANALYSIS:
--------------
INLINE VIEW OR DERIVED TABLE
If you are writing a sub query in FROM clause , its called inline view.
select name,sal FROM(select name,sal from emp order by sal desc) where rownum=2;
Inline view always should contain sort option order by. Rownumber comparision always in the outer query.
select name,salary FROM(select name,salary from ex_emp order by salary DESC) where rownum<=2
SECOND HIGHEST SALARY
---------------------
select name,salary FROM(select rownum n,name,salary from
(select name,salary from ex_emp order by salary DESC)
order by salary DESC) where n=2
How to find second highest salary (if 2 people are there then it will get 2 people with 2nd highest salary).
select * from ex_details a where &n = (select count(distinct salary) from ex_details where salary>=a.salary);
****enter which highest salary u want.it will get for you.
Monday, October 11, 2010
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment