如何在单个SQLAlchemy查询中选择多个值

时间:2018-07-19 22:50:02

标签: python sql sqlalchemy

我想知道如何在一个SQLAlchemy查询中选择多个内容。例如:

我在SQL中有以下查询:

SELECT count(1) as total_count,
sum(A.status = B.status) as rows_matching,
sum(A.status != B.status) as rows_different,
FROM (SELECT * FROM executions where execution_type = 'execution1') as A 
JOIN (SELECT * FROM executions where execution_type = 'execution2') as B 
ON (B.original_execution_id = A.execution_id)

我可以尝试在上述查询中复制多个选择。

我目前通过执行以下操作为联接生成了SQLAlchemy代码:

Default = aliased(Execution, name="default")
query = Execution.create_filter_query(execution_type='execution2', **kwargs)
query = query.join(Default, Default.execution_id == Execution.original_execution_id)

如何在上述代码的基础上生成所需的查询?

0 个答案:

没有答案