【发布时间】:2016-07-01 11:54:08
【问题描述】:
我正在寻找将以下 sql 语句转换为 sql alchemy
select c1.id, c1.repository, c1.branch, c1.failed_step, c1.stop_time
from completed_builds as c1
where c1.stop_time = (
select max(c2.stop_time)
from completed_builds as c2
where c1.branch = c2.branch
and c1.repository = c2.repository
)
and c1.repository in ('flex', 'mob', 'tv')
and c1.branch in ('stage', 'int')
order by c1.repository, c1.branch
这会输出具有最高 stop_time 值的唯一分支 + 存储库对。
非常感谢!
【问题讨论】:
-
select distinct completed_builds.* from completed_builds left join (select c2.* from completed_builds as c1, completed_builds as c2 where c1.branch = c2.branch and c1.repository = c2.repository and c1.stop_time > c2.stop_time ) as NOT_LARGEST ON completed_builds.id = NOT_LARGEST.id where NOT_LARGEST.id is null这个sql语句做同样的事情。不确定此语句是否更容易转换为 sqlalchemy? -
请使用问题上的编辑链接添加更多信息。
-
我们无法为您编写代码。你试过什么?
-
多个 where 语句有问题吗? than you might find your answer here 使用
sqlalchemy.and_
标签: sql sqlalchemy