Ради интереса посмотрите в сторону
docs.peewee-orm.com/en/latest/peewee/querying.html#counting-records Tweet.select().where(Tweet.id > 50).count()50
так же https://stackoverflow.com/questions/40725044/peewe...
Возможно ответ вот
sqlalchemy.org .havingq = session.query(User.id).\
join(User.addresses).\
group_by(User.id).\
having(func.count(Address.id) > 2)
но что то не получается запрос сделать какой нужен))
how-to-count-rows-with-select-with-sqlalchemy
бесплатный курс sql functions про count, sum sqlalchemy core
ampus.datacamp.com courses introduction-to-relatio...# Import func
from sqlalchemy import func
# Build a query to select the state and count of ages by state: stmt
stmt = select([census.columns.state, func.count(census.columns.age)])
# Group stmt by state
stmt = stmt.group_by(census.columns.state)
# Execute the statement and store all the records: results
results = connection.execute(stmt).fetchall()
# Print results
print(results)
# Print the keys/column names of the results returned
print(results[0].keys())