Home » SQL & PL/SQL » SQL & PL/SQL » Clarification on 'N' th High/Low salary
Clarification on 'N' th High/Low salary [message #232770] Mon, 23 April 2007 04:16 Go to next message
diku
Messages: 23
Registered: April 2007
Junior Member
Hi,

Apologies at the outset for trying the thread for the umpttenth time. I just need a clarification regarding usage criteria here.
I can use the RANK function here and there are a zillion other ways to tackle this.
And I can use a plain old fashioned query like


select o.empno,o.ename,o.sal 
from emp o
where 3 > (select count(distinct(sal)) from emp where o.sal <sal)
order by sal desc


I assume I don't need to give the EMP table details
I want to know since I don't get any significant cost/time benefit why should I use the RANK function when I can achieve the same? Or is the standard(read elegant) way to do things

Apologies again for the trouble.

Re: Clarification on 'N' th High/Low salary [message #232787 is a reply to message #232770] Mon, 23 April 2007 05:00 Go to previous message
Michel Cadot
Messages: 64152
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Read your query.
You scan emp table twice.
Using analytic functions, you scan it only once.

This is the reason to use rank.

Regards
Michel
Previous Topic: like function
Next Topic: Indexes - Disdavantages
Goto Forum:
  


Current Time: Sat Dec 10 10:47:45 CST 2016

Total time taken to generate the page: 0.10009 seconds