Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> Re: Select Distinct (was top N or rewriting MAX)

Re: Select Distinct (was top N or rewriting MAX)

From: AWILSON <awilson_at_rci.rogers.com>
Date: 1997/01/22
Message-ID: <32E68252.7FBD@rci.rogers.com>#1/1

Solomon.Yakobson_at_entex.com wrote:
>
> Yes, duplicates weren't mentioned explicitly. But they are real
> life and the original question is real life question.
> E.g. question how to select top 10 customers based on spent $
> amount already assumes possibility of duplicates (two or more
> customers spent same $ amount), etc.
>

OK try this then:

begin
  declare
    mycount number;
    max_count number := 10;

    ccur is

      select customer_no
        from customers
      order by amout_spend desc;

  begin
    for crec in ccur loop

      mycount := mycount + 1;
      if mycount > max_count then
        exit loop;
      end if;
      dbms_output.put_line(to_char(customer_number));
    end loop;
  end;
end;

The above reflect my personal views and in no way are connected with whomsoever I may be working for at this particular point in time.  
Alan Wilson                              Help fight continental drift.
======================================================================
Received on Wed Jan 22 1997 - 00:00:00 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US