substituted havingClause in the same way as resultExprs to prevent " HAVING clause not produced by aggregation output" error