I'm confused, this doesn't seem right. This article, and several of the comments here, suggest that you cannot reference things calculated during SELECT in the HAVING field. But you can.
As a quick demo, pick your favorite table and run:
SELECT 2+2 as num FROM <table> HAVING num > 3;
this will return as many 4s as there are rows in the table SELECT 2+2 as num FROM <table> HAVING num > 4;
this will return 0 rows.