Re: Newbie SQL question (Top 10 values)

From: Donna Kray <kray.donna_at_mlink.motors.ge.com>
Date: 1996/01/16
Message-ID: <4dg8hc$1bn_at_crissy.ge.com>#1/1


mudhens_at_cyberramp.net (RAC) wrote:
>Rob Weeks <rweeks_at_kodak.com> wrote:
>
>>How in the heck do I write a query that either returns the top 10% or
>>top ten values of a specific field (sales information for instance)?
>
>You can get the top ten values by (1) sorting in descending order the
>field that you want to see and (2) adding an additional where clause
>stating "and rownum < 11" For example, you query might look like
>
>select sales
>from table_name
>where rownum < 11
>order by sales desc
>
>Hope this helps.
>



ROWNUM is assigned to retreived rows *before* any ordering is done in the ORDER BY clause. Thus, this query will not return what you want reliably.

I don't, however, have any other solution, just a caveat.

DL Kray Received on Tue Jan 16 1996 - 00:00:00 CET

Original text of this message