Apply one or more GROUP BY criterion to the query and return the newly resulting :class:`_query.Query`. All existing GROUP BY settings can be suppressed by passing ``None`` - this will suppress any GROUP BY configured on mappers as well. .. seealso::
(
self,
__first: Union[
Literal[None, False, _NoArg.NO_ARG],
_ColumnExpressionOrStrLabelArgument[Any],
] = _NoArg.NO_ARG,
*clauses: _ColumnExpressionOrStrLabelArgument[Any],
)
| 2048 | |
| 2049 | @_generative |
| 2050 | def group_by( |
| 2051 | self, |
| 2052 | __first: Union[ |
| 2053 | Literal[None, False, _NoArg.NO_ARG], |
| 2054 | _ColumnExpressionOrStrLabelArgument[Any], |
| 2055 | ] = _NoArg.NO_ARG, |
| 2056 | *clauses: _ColumnExpressionOrStrLabelArgument[Any], |
| 2057 | ) -> Self: |
| 2058 | """Apply one or more GROUP BY criterion to the query and return |
| 2059 | the newly resulting :class:`_query.Query`. |
| 2060 | |
| 2061 | All existing GROUP BY settings can be suppressed by |
| 2062 | passing ``None`` - this will suppress any GROUP BY configured |
| 2063 | on mappers as well. |
| 2064 | |
| 2065 | .. seealso:: |
| 2066 | |
| 2067 | These sections describe GROUP BY in terms of :term:`2.0 style` |
| 2068 | invocation but apply to :class:`_orm.Query` as well: |
| 2069 | |
| 2070 | :ref:`tutorial_group_by_w_aggregates` - in the |
| 2071 | :ref:`unified_tutorial` |
| 2072 | |
| 2073 | :ref:`tutorial_order_by_label` - in the :ref:`unified_tutorial` |
| 2074 | |
| 2075 | :meth:`_sql.Select.group_by` - v2 equivalent method. |
| 2076 | |
| 2077 | """ |
| 2078 | |
| 2079 | for assertion in (self._no_statement_condition, self._no_limit_offset): |
| 2080 | assertion("group_by") |
| 2081 | |
| 2082 | if not clauses and (__first is None or __first is False): |
| 2083 | self._group_by_clauses = () |
| 2084 | elif __first is not _NoArg.NO_ARG: |
| 2085 | criterion = tuple( |
| 2086 | coercions.expect(roles.GroupByRole, clause) |
| 2087 | for clause in (__first,) + clauses |
| 2088 | ) |
| 2089 | self._group_by_clauses += criterion |
| 2090 | return self |
| 2091 | |
| 2092 | @_generative |
| 2093 | @_assertions(_no_statement_condition, _no_limit_offset) |
no outgoing calls