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

Home -> Community -> Usenet -> c.d.o.tools -> Re: find the second largest element

Re: find the second largest element

From: Wiktor <xxxwiktor_at_legnica.americanos.com.pl>
Date: Mon, 27 Nov 2000 11:51:58 +0100
Message-ID: <8vtf5a$g6q$1@kujawiak.man.lodz.pl>

> Dear friend, I like to write a query that will find the largest and the
 second
> largest values of a column in a group by setting.
>

In a single statement U can try:

SELECT DISTINCT ID,SAL FROM <TABLE> A
WHERE 2>=(SELECT COUNT(DISTINCT SAL)FROM <TABLE> B

          WHERE A.SAL<=B.SAL AND B.ID=A.ID) ORDER BY ID,SAL DESC and the output U get:
ID SAL
1 max
1 secmax
2 max
2 secmax
etc...
Pozdrowionka :-)
Wiktor

--
_____________
NO SPAM
WYTNIJ XXX
CUT       XXX
Received on Mon Nov 27 2000 - 04:51:58 CST

Original text of this message

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