Re: [Q] Daves's top 10 SQL question

From: Mike Madland <mikemad_at_asymetrix.com>
Date: 1996/03/19
Message-ID: <4in93o$h3s_at_loki.asymetrix.com>#1/1


youngpa_at_statcan.ca (Paul Young) wrote:

>Dave has a catalogue of Stupid Pet Tricks tapes. Each has a NAME and
>an outrageous SCORE factor (higher is better and there's no limit).
>Now Dave has hundreds of these entries, say in an Oracle table.
>On his next greatest hits of David Letterman show, he wants to show
>only the best 10.
 

>Help Dave find a solution and code the SQL query.
 

>But seriously, how can you code a SQL query to first order records
>greatest to least then pick out only a pre-selected number of them
>without prior knowledge of their distribution. This strikes me as
>a common, even simple thing to do, but I can't see how to do it, and
>I've written some pretty twisted queries.
 

>Your assistance with this is appreciated. Thank you.

connect scott/tiger

select ename, sal
  from emp
 where -sal in

       (select -sal
          from emp)

   and rownum < 11
/

>PGY (Opinions expressed are mine and mine alone, sorry Dave)
>################################################################
># Paul Young #
># youngpa_at_statcan.ca #
># Statistics Canada #
>################################################################
Received on Tue Mar 19 1996 - 00:00:00 CET

Original text of this message