Fix the HAVING AVG bug