Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Cursor

Re: Cursor

From: K Stahl <BlueSax_at_Unforgetable.com>
Date: 2000/03/30
Message-ID: <38E3510C.2B9AD691@Unforgetable.com>#1/1

Steven R& Don E Fuller wrote:
>
> I need to limit my return the top 20 and the bottom 20 percent of
> records, what is the best way to comlpete this type of a request?

How do you define "top 20" and "bottom 20"? There really is no such thing in oracle except in the way that the business rules for a particular table are established by your company policy - oracle in itself merely contains a collection of rows and it is up to the programmer to determine the selection criteria.

Having said that, here is an example of how this MIGHT be done.

Say that you have a list of 100 students and that each student is assigned a 6-digit student-id and value which represents their ranking in their class relative to other students in the class. As a result, the highest 20% of the students would have rankings 1-20 and the bottom 20% would have rankings 81-100. So, we'd lay out a table STUDRANKS like this

STUDENT_ID varchar(6)
RANK number(3)

To extract the top and bottom 20% we do a query like this:

select studentid,rank
from studranks
where rank <= .20
union
select studentid,rank
from studranks
where rank > .80 Received on Thu Mar 30 2000 - 00:00:00 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US