task_results = db.Table('task_results',
db.Model.metadata,
db.Column('task_id', db.Integer, db.ForeignKey('tasks.id')),
db.Column('account_id', db.Integer, db.ForeignKey('account_details.id')))
class Task(db.Model):
__tablename__ = 'tasks'
id = db.Column(db.Integer, primary_key=True)
accounts = db.relationship('AccountDetail', secondary=brut_task_results)
class AccountDetail(db.Model):
__tablename__ = 'account_details'
id = db.Column(db.Integer, primary_key=True)
SELECT * FROM tasks WHERE (SELECT COUNT(*) FROM task_results WHERE tasks.id = task_results.task_id) < 100
Ради интереса посмотрите в сторону
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...
q = session.query(User.id).\
join(User.addresses).\
group_by(User.id).\
having(func.count(Address.id) > 2)
# 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())