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

Home -> Community -> Usenet -> c.d.o.misc -> SQL statement question. please help ...

SQL statement question. please help ...

From: Jimmy <c6635500_at_comp.polyu.edu.hk>
Date: Tue, 14 Sep 1999 21:45:46 -0700
Message-ID: <37DF247A.2C5DEC07@comp.polyu.edu.hk>


Hello all,

    I want to do a query by following requirements:

    I want to retrieve the distinct value of AAA of table T_A if the count(distinct(AAA)) of this SQL statmenet is smaller than 500, otherwise returns 'TOO MANY';

    i.e. select distinct(AAA) from T_A if count(distinct(AAA)) <= 500;

         select 'TOO MANY' from T_A if count(distinct(AAA)) > 500;

    I don't know how to write a SQL statement to do the above requirements. Is is possible to do this by one SQL statement? (and this SQL statment has the shortest response time and AAA may or may not the index of the table T_A)

    Does Oracle needs two table scan in using one SQL statement to do the above query? First, scan the table T_A and get the count(distinct(AAA)). If <=500, then scan the table again and retrieve the distinct(AAA), am I right?

Thanks,
Jimmy Received on Tue Sep 14 1999 - 23:45:46 CDT

Original text of this message

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