Didn't expect <text> after the HAVING clause.
The expression or clause after the HAVING clause in your SQL statement isn't valid.