Queries "group by" that contain a subquery with an aggregate function returned the wrong result in some cases.