MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / having

Method having

lib/sqlalchemy/orm/query.py:2094–2122  ·  view source on GitHub ↗

r"""Apply a HAVING criterion to the query and return the newly resulting :class:`_query.Query`. :meth:`_query.Query.having` is used in conjunction with :meth:`_query.Query.group_by`. HAVING criterion makes it possible to use filters on aggregate functions li

(self, *having: _ColumnExpressionArgument[bool])

Source from the content-addressed store, hash-verified

2092 @_generative
2093 @_assertions(_no_statement_condition, _no_limit_offset)
2094 def having(self, *having: _ColumnExpressionArgument[bool]) -> Self:
2095 r"""Apply a HAVING criterion to the query and return the
2096 newly resulting :class:`_query.Query`.
2097
2098 :meth:`_query.Query.having` is used in conjunction with
2099 :meth:`_query.Query.group_by`.
2100
2101 HAVING criterion makes it possible to use filters on aggregate
2102 functions like COUNT, SUM, AVG, MAX, and MIN, eg.::
2103
2104 q = (
2105 session.query(User.id)
2106 .join(User.addresses)
2107 .group_by(User.id)
2108 .having(func.count(Address.id) > 2)
2109 )
2110
2111 .. seealso::
2112
2113 :meth:`_sql.Select.having` - v2 equivalent method.
2114
2115 """
2116
2117 for criterion in having:
2118 having_criteria = coercions.expect(
2119 roles.WhereHavingRole, criterion
2120 )
2121 self._having_criteria += (having_criteria,)
2122 return self
2123
2124 def _set_op(self, expr_fn: Any, *q: Query[Any]) -> Self:
2125 list_of_queries = (self,) + q

Callers 15

test_five_aMethod · 0.45
test_five_bMethod · 0.45
test_exists_methodMethod · 0.45
test_inMethod · 0.45
test_havingMethod · 0.45
test_fiveMethod · 0.45

Calls

no outgoing calls

Tested by 15

test_five_aMethod · 0.36
test_five_bMethod · 0.36
test_exists_methodMethod · 0.36
test_inMethod · 0.36
test_havingMethod · 0.36
test_fiveMethod · 0.36