Having in select clause appends before WHERE clause that cause an synax error. And it inserts column name only, but it could be an expression too.