'apply a HAVING criterion to the query and return the
newly resulting :class:`.Query`.
:meth:`~.Query.having` is used in conjunction with :meth:`~.Query.group_by`.
HAVING criterion makes it possible to use filters on aggregate
functions like COUNT, SUM, AVG, MAX, and MIN, eg.::
q = session.query(User.id).\
join(User.addresses).\
group_by(User.id).\
having(func.count(Address.id) > 2)'

@_generative(_no_statement_condition, _no_limit_offset)
def having(self, criterion):

    if isinstance(criterion, util.string_types):
        criterion = sql.text(criterion)
    if ((criterion is not None) and (not isinstance(criterion, sql.ClauseElement))):
        raise sa_exc.ArgumentError('having()    argument    must    be    of    type    sqlalchemy.sql.ClauseElement    or    string')
    criterion = self._adapt_clause(criterion, True, True)
    if (self._having is not None):
        self._having = (self._having & criterion)
    else:
        self._having = criterion
