Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Simple Top N question
A copy of this was sent to "Babu" <vsbabu_at_erols.com>
(if that email address didn't require changing)
On Wed, 10 Nov 1999 11:45:15 -0500, you wrote:
>SELECT
> A.customer
> , MAX(A.order_num) order_num
> , MAX(A.quantity) quantity
>FROM
> orders A
>GROUP BY
> A.customer
>/
>
>should work. Or more elaborately (and slowly)
>
no -- that will get SOME max order_num and SOME max quantity -- the order num and quantity will probably *NOT* be from the same rows (you'll get an order_num from one row -- the one with the max order_num and a quantity from some other row, they are no correlated)
>SELECT
> A.customer
> , MAX(A.order_num) order_num
> , A.quantity
>FROM
> orders A
>WHERE
> A.quantity >= (
> SELECT
> MAX(B.quantity)
> FROM
> orders B
> WHERE
> B.customer = A.customer
> )
>GROUP BY
> A.customer
> , A.quantity
>/
That is one that would work...
--
See http://osi.oracle.com/~tkyte/ for my columns 'Digging-in to Oracle8i'...
Current article is "Part I of V, Autonomous Transactions" updated June 21'st
Thomas Kyte tkyte_at_us.oracle.com Oracle Service Industries Reston, VA USA
Opinions are mine and do not necessarily reflect those of Oracle Corporation Received on Wed Nov 10 1999 - 12:38:34 CST
![]() |
![]() |