Re: SQL PUZZLE: selecting top 50 salaries in a table

From: Van Messner <vmessner_at_netaxis.com>
Date: Thu, 21 Oct 1999 19:36:13 -0400
Message-ID: <9sNP3.26581$E_1.1430780_at_typ11.nn.bcandid.com>


[Quoted] [Quoted] I don't have Oracle in front of me but please try below where n is how many [Quoted] [Quoted] top records to select, MySalaryTable has the salary information and [Quoted] [Quoted] determinant is any other condition (the 50 top salaries for 1997 for [Quoted] example). This query should allow for ties, which in the case of salaries, are likely to occur.

SELECT
  sal1.salary,
  (SELECT
     COUNT(DISTINCT salary)
   FROM
      MySalaryTable sal2
   WHERE

[Quoted]       sal2.salary >= sal1.salary
[Quoted] [Quoted]       and sal2.determinant = sal1.determinant) as ranking
FROM
   MySalaryTable sal1
Where

   ranking <= &n
;

Van

NetComrade <andreyNSPAM_at_bookexchange.net> wrote in message news:380f8e89.268436409_at_news.earthlink.net...
> Well.. we know how to select top salary, which is select max(salary),
> but how would I select top 50 records?
> ---------------
> Andrey Dmitriev eFax: (978) 383-5892 Daytime: (917) 373-5417
> AOL: NetComrade ICQ: 11340726 remove NSPAM to email
>
Received on Fri Oct 22 1999 - 01:36:13 CEST

Original text of this message