You can use group_by clauses with the following queries:

It is used in combination with aggregate functions - Count is currently supported.


In the following query, we get a count of the number of bands per manager:

>>> from import Count

>>> await
...     Count(Band.manager)
... ).group_by(
...     Band.manager
... )

    {"": "Graydon", "count": 1},
    {"": "Guido", "count": 1}


class Optional[Column] = None, alias: str = 'count')

Used in conjunction with the group_by clause in Select queries.

If a column is specified, the count is for non-null values in that column. If no column is specified, the count is for all rows, whether they have null values or not.

await, Count()).group_by(

# We can use an alias. These two are equivalent:

await, Count(alias="total")