Re: Can I do this using SQL?

From: Knut Stolze <stolze_at_de.ibm.com>
Date: Thu, 09 Feb 2006 17:43:40 +0100
Message-ID: <dsfrfs$tvc$2_at_lc03.rz.uni-jena.de>


dhruv wrote:

> Hi,
> Thanks a lot! Ok, so let me get this straight... If I have a count(),
> min(), max, avg() on the projection list, then I can use it with group
> by and the aggregate will be applied on EACH GROUP? Also, is ORDER BY
> always applied last(on the final result set).

Yes.

> Also, if I have a HAVING clause, will it too be applied on each GROUP?

Yes.

> If so, then can I always emulate HAVING by using subqueries, by
> projecting the fields after the HAVING keyword, and putting the
> condition after the HAVING keyword in the WHERE of the outher select?

I haven't run into any situation where this could not be done.

Btw, getting the first n rows can also be achieved by using a recursive common table expression to number the rows and then select the rows based on those numbers.

-- 
Knut Stolze
Received on Thu Feb 09 2006 - 17:43:40 CET

Original text of this message