My script is like this:
$query = Doctrine_Query::create () ->select(\'count(p.product_id) as num_a\') ->from ( \'ProductComments p\'
This would not be valid SQL.
SQL standard state that SELECT will be logically executed after having. So You need to repeat aliased code in having.
having
Good advice. As long as You work with SQL consuming DBs stick as closely to SQL as possible.