Subject | Re: [firebird-support] Need help with unexpected results from a query |
---|---|
Author | Helen Borrie |
Post date | 2004-03-12T01:16:37Z |
At 04:27 PM 11/03/2004 -0800, you wrote:
search criteria are not part of the output.
Use a WHERE clause for search criteria. Use a HAVING clause to limit the
output of aggregations. For example, in your case
...HAVING COUNT(ZIPCODE_ANALYSIS.C_ID) < 100
Something like
...HAVING ZIPCODE_ANALYSIS.ZIP = <something>
would be legal (logically) but it is wasteful, because HAVING operates on
output.
some illogical things with GROUP BY. I think Fb 1.0 is less tolerant of
bad GROUP BY clauses than IB 6 but it still allows some illogical things.
/heLen
>Hi All,Exactly right. See Alexandre's reply.
>
>I have a query that has me stomped, to be exact it's the HAVING clause :-)
>SELECTIn your example, the HAVING clause can't do anything at all because its
> ZIPCODE_ANALYSIS.ACTIVITY_NAME AS ActivityName,
> ZIPCODE_ANALYSIS.ZIP AS CustomerZip,
> COUNT(ZIPCODE_ANALYSIS.C_ID) AS CountCID
>FROM ZIPCODE_ANALYSIS
>GROUP BY
> ZIPCODE_ANALYSIS.ACTIVITY_NAME,
> ZIPCODE_ANALYSIS.ZIP
>HAVING
> (ZIPCODE_ANALYSIS.ACTIVITY_DATE BETWEEN '02/01/2004' AND '02/29/2004')
>ORDER BY 1
>
>
>Can anybody explain to me what the hell is going on?
search criteria are not part of the output.
Use a WHERE clause for search criteria. Use a HAVING clause to limit the
output of aggregations. For example, in your case
...HAVING COUNT(ZIPCODE_ANALYSIS.C_ID) < 100
Something like
...HAVING ZIPCODE_ANALYSIS.ZIP = <something>
would be legal (logically) but it is wasteful, because HAVING operates on
output.
>Btw, I am using IB 6 and haven't fired up FB yet, but I assume that theIt would (rightly) cause an exception in Firebird 1.5) but IB 6 lets you do
>results
>will be the same.
some illogical things with GROUP BY. I think Fb 1.0 is less tolerant of
bad GROUP BY clauses than IB 6 but it still allows some illogical things.
/heLen