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

Home -> Community -> Mailing Lists -> Oracle-L -> Top N query

Top N query

From: Koivu, Lisa <lkoivu_at_qode.com>
Date: Wed, 10 Jan 2001 14:59:37 -0500
Message-Id: <10737.126320@fatcity.com>


This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible.

------_=_NextPart_001_01C07B3F.DE2CDE94
Content-Type: text/plain;

        charset="iso-8859-1"

OK, I apologize in advance, I know this has been discussed many times.

I need to generate the top N, in this case 3, values for a query, like the example shown below. It has to be done in SQL, because I need to return this as a refcursor. (OPEN refcurcor FOR...)

category1     10
category1     14
category1     2
category1     25
category2     14
category2    13
category2     55

category2 5
category3 14
category3 1
category4 5

I need to display this:

category1 25
category1 14
category1 10
category2 55
category2 14
category2 13
category3 14
category3 1
category4 5

Can you hear me cursing....

Thanks in advance for any suggestions.

Lisa Rutland Koivu
Oracle Database Administrator
Qode.com
4850 North State Road 7
Suite G104
Fort Lauderdale, FL 33319

V: 954.484.3191, x174
F: 954.484.2933 
C: 954.658.5849

http://www.qode.com

"The information contained herein does not express the opinion or position of Qode.com and cannot be attributed to or made binding upon Qode.com."

------_=_NextPart_001_01C07B3F.DE2CDE94
Content-Type: text/html;

        charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV=3D"Content-Type" CONTENT=3D"text/html; =
charset=3Diso-8859-1">
<META NAME=3D"Generator" CONTENT=3D"MS Exchange Server version =
5.5.2650.12">
<TITLE>Top N query</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=3D2 FACE=3D"Arial">OK, I apologize in advance, I know =
this has been discussed many times. </FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">I need to generate the top N, in this =
case 3, values for a query, like the example shown below.&nbsp; It has = to be done in SQL, because I need to return this as a refcursor.&nbsp; = (OPEN refcurcor FOR...) </FONT></P>

<P><FONT SIZE=3D2 FACE=3D"Arial">category1&nbsp;&nbsp;&nbsp;&nbsp; =
10</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">category1&nbsp;&nbsp;&nbsp;&nbsp; =
14</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">category1&nbsp;&nbsp;&nbsp;&nbsp; =
2</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">category1&nbsp;&nbsp;&nbsp;&nbsp; =
25</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">category2&nbsp;&nbsp;&nbsp;&nbsp; =
14</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">category2&nbsp;&nbsp;&nbsp; 13</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">category2&nbsp;&nbsp;&nbsp;&nbsp; =
55</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">category2&nbsp;&nbsp;&nbsp; 5</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">category3&nbsp;&nbsp;&nbsp; 14</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">category3&nbsp;&nbsp;&nbsp; 1</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">category4&nbsp;&nbsp;&nbsp; 5</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">I need to display this:</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">category1&nbsp; 25</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">category1&nbsp; 14</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">category1&nbsp; 10</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">category2&nbsp; 55</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">category2&nbsp; 14</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">category2&nbsp; 13</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">category3&nbsp; 14</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">category3&nbsp; 1</FONT>
<BR><FONT SIZE=3D2 FACE=3D"Arial">category4&nbsp; 5</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">Can you hear me cursing....</FONT>
</P>

<P><FONT SIZE=3D2 FACE=3D"Arial">Thanks in advance for any =
suggestions.&nbsp; </FONT>
</P>

<P><B><FONT SIZE=3D1 FACE=3D"Arial">Lisa Rutland Koivu</FONT></B>
<BR><FONT SIZE=3D1 FACE=3D"Arial">Oracle Database Administrator</FONT>
<BR><FONT SIZE=3D1 FACE=3D"Arial">Qode.com</FONT>
<BR><FONT SIZE=3D1 FACE=3D"Arial">4850 North State Road 7</FONT>
<BR><FONT SIZE=3D1 FACE=3D"Arial">Suite G104</FONT>
<BR><FONT SIZE=3D1 FACE=3D"Arial">Fort Lauderdale, FL&nbsp; =
33319</FONT>
</P>

<P><FONT SIZE=3D1 FACE=3D"Arial">V: 954.484.3191, x174</FONT>
<BR><FONT SIZE=3D1 FACE=3D"Arial">F: 954.484.2933 </FONT>
<BR><FONT SIZE=3D1 FACE=3D"Arial">C: 954.658.5849</FONT>
<BR><FONT SIZE=3D1 FACE=3D"Arial"><A HREF=3D"http://www.qode.com" =
TARGET=3D"_blank">http://www.qode.com</A></FONT>
</P>

<P><I><FONT COLOR=3D"#000000" SIZE=3D1 FACE=3D"Arial">&quot;The =
information contained herein does not express the opinion or position = of Qode.com and cannot be attributed to or made binding upon = Received on Wed Jan 10 2001 - 13:59:37 CST

Original text of this message

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