Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.tools -> Re: find the second largest element
> 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 XXXReceived on Mon Nov 27 2000 - 04:51:58 CST
![]() |
![]() |