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])
| 2122 | @_generative |
| 2123 | @_assertions(_no_statement_condition, _no_limit_offset) |
| 2124 | def having(self, *having: _ColumnExpressionArgument[bool]) -> Self: |
| 2125 | r"""Apply a HAVING criterion to the query and return the |
| 2126 | newly resulting :class:`_query.Query`. |
| 2127 | |
| 2128 | :meth:`_query.Query.having` is used in conjunction with |
| 2129 | :meth:`_query.Query.group_by`. |
| 2130 | |
| 2131 | HAVING criterion makes it possible to use filters on aggregate |
| 2132 | functions like COUNT, SUM, AVG, MAX, and MIN, eg.:: |
| 2133 | |
| 2134 | q = ( |
| 2135 | session.query(User.id) |
| 2136 | .join(User.addresses) |
| 2137 | .group_by(User.id) |
| 2138 | .having(func.count(Address.id) > 2) |
| 2139 | ) |
| 2140 | |
| 2141 | .. seealso:: |
| 2142 | |
| 2143 | :meth:`_sql.Select.having` - v2 equivalent method. |
| 2144 | |
| 2145 | """ |
| 2146 | |
| 2147 | for criterion in having: |
| 2148 | having_criteria = coercions.expect( |
| 2149 | roles.WhereHavingRole, criterion |
| 2150 | ) |
| 2151 | self._having_criteria += (having_criteria,) |
| 2152 | return self |
| 2153 | |
| 2154 | def _set_op(self, expr_fn: Any, *q: Query[Any]) -> Self: |
| 2155 | list_of_queries = (self,) + q |
no outgoing calls