Re: Many aggregates in one query

From: Heinz Huber <hhuber_at_racon-linz.at>
Date: Fri, 17 Aug 2001 14:14:33 +0200
Message-ID: <3B7D0AA9.4F9298C4_at_racon-linz.at>


Matti Teppo wrote:
>
> > If you're using mySQL you can use the LIMIT clause which is specific to this
> > DBMS and do the following :
> > SELECT wsid, count(wsid) AS rowcnt
> > FROM test
> > GROUP BY wsid
> > ORDER BY rowcnt ASC
> > LIMIT 1;
> >
> > You just get the first result.
>
> Thank you, but I use Sybase so LIST is not available.

If you're using ASA 7 (and perhaps also 6), you can use the following query: SELECT MIN(wsid), MIN(rowcnt)
 FROM (SELECT wsid, COUNT(wsid) AS rowcnt

       FROM test
       GROUP BY wsid
       HAVING COUNT(wsid) = MIN(COUNT(wsid)) t;

Perhaps it works for other DMBSs, too.

hth,
Heinz Received on Fri Aug 17 2001 - 14:14:33 CEST

Original text of this message