我正在努力理解如何在SQLAlchemy中使用针对单个表的left outer join。在
我有以下SQL查询:
select r1.*, r1.result as result1, r2.result as result2
from
(
select * from participation
where day_id = 1
and sport_id = 1
)
r1
left join
(
select * from participation
where day_id = 3
and sport_id = 1
)
r2
on r1.participant_id = r2.participant_id
结果如下:
^{pr2}$我现在有以下SQLAlchemy脚本:
results = db.session.query(Participation). \
<maybe something here?>
all()
但这会将每个结果作为自己的行返回。有人能指出我需要做些什么吗?在
根据给定的信息,您只需alias a subquery两次和{a2}:
相关问题 更多 >
编程相关推荐