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])
| 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 |
no outgoing calls