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 -> Using a MIN with a COUNT

Using a MIN with a COUNT

From: martinl <laflamme_at_iname.com>
Date: Tue, 23 Nov 1999 10:04:37 -0500
Message-ID: <C_x_3.1088$ym.59835@wagner.videotron.net>


Greetings to all,

    I have a small question regarding the combined use of the MIN and COUNT set functions. I have a querry which looks like this:

    SELECT COUNT(nbDesks), nbDesks
    FROM rooms
    GROUP BY (nbDesks)
    ORDER BY 1;     This will return the following results:

COUNT(NBDESKS) NBDESKS

-------------- --------------------
             2             d2
             3             d1
             3             d4
             4             d3

    Now, using the COUNT(nbDesks) column as a referrence, I would like to retrieve only the min value of this table, i.e the first line. My question is: is there any way to use the MIN function with the COUNT function to achieve this? As a first try, I attempted to combine them in the following
way:

    SELECT MIN(COUNT(nbDesks)), nbDesks     FROM rooms
    GROUP BY (nbDesks)
    ORDER BY 1;     But that didn't work. Anybody has an idea? I know I could use a cursor to retrieve the first row but I was wondering if there was a more direct way to do this.

    Thanks a lot,
    Martin Received on Tue Nov 23 1999 - 09:04:37 CST

Original text of this message

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