我需要能够过滤子查询中的多列行
在sql中,这就像
where (account_details.account_detail_id, tasks.base_action_type_id) IN
(
SELECT tasks.account_detail_id , tasks.base_action_type_id
FROM tasks
WHERE tasks.dt_created > now() - interval '1 day'
GROUP BY tasks.account_detail_id ,tasks.base_action_type_id
HAVING count(tasks.account_detail_id) < 3
)
但是我找不到有关sqlalchmey
格式的任何信息我试过
dayBefore = datetime.utcnow() - timedelta(hours=24)
subquery = Tasks.query.with_entities(Tasks.account_detail_id, Tasks.base_action_type_id).\
filter(Tasks.dt_created > dayBefore).\
group_by(Tasks.account_detail_id, Tasks.base_action_type_id).\
having(func.count(Tasks.account_detail_id) < 3)
sql = AccountDetails.query.join(Tasks, Tasks.account_detail_id == AccountDetails.account_detail_id).\
filter(AccountDetails.account_detail_id == 3, (AccountDetails.account_detail_id,Tasks.base_action_type_id).in_(subquery))
注意这一行
(AccountDetails.account_detail_id,Tasks.base_action_type_id).in_(subquery)
但这只是错误的无效语法
答案 0 :(得分:0)
Using sqlalchemy to query using multiple column where in clause