The wrong query result was returned from a Select with two levels of nested scalar sub-queries with aggregates. The error was generated by a statement with a non-GroupBy expression in the main Select and a GroupBy expression in a scalar sub-query Select. The logic has been updated to properly handle this situation.