Icon View Incident Report

Serious Serious
Reported By: Herbert Sitz
Reported On: 7/24/2003
For: Version 3.24 Build 1
# 1400 SQL HAVING Clause Using Wrong Aggregate Expression for Evaluation and Filtering

I'm getting wacky results when using different combinations of two different aggregate criteria in a HAVING clause.

Example 1:
-----------------------------------

SELECT c.LastName, c.FirstName, sum(d.amount) as Sum_of_Amount,
count(d.amount) as Count_of_Amount
FROM Contacts c
INNER JOIN Donations d ON (c.ContactID=d.ContactID)
GROUP BY c.LastName, c.FirstName
HAVING (count(d.amount) > 3 )

This statement should return records that have count(d.amount) > 3. Instead it is ignored and returns all records regardless of count(d.amount).

Example 2:
-------------------------------------

SELECT c.LastName, c.FirstName, count(d.amount) as Count_of_Amount,
sum(d.amount) as Sum_of_Amount
FROM Contacts c
INNER JOIN Donations d ON (c.ContactID=d.ContactID)
GROUP BY c.LastName, c.FirstName
HAVING (sum(d.amount) > 1000 )

This statement should return all records with sum(d.amount) > 1000. Instead it returns an empty set.

The inaccuracies in Example 1 and 2 seem to be tied to the order of the Count_of_Amount and Sum_of_Amount result fields. If I reverse the order of those two fields in either example, the proper result set is returned. I'm also getting inaccurate results when I combine the two criteria in a single HAVING clause, but I think the two examples I've given get at the essential problem in all of them.


Resolution Resolution
Fixed Problem on 7/25/2003 in version 3.25 build 1
Image