我有以下sql代码:
SELECT t1.*
FROM table1 t1
INNER JOIN table2 t2
ON t1.id = t2.sample_id
GROUP BY t1.id
HAVING NOW() > (SELECT end FROM table2 WHERE start =
max(t2.start)) + (t1.time::text||' minute')::interval
我需要像这样在sqlalchemy中重写此代码:
Table1.query
.join(Table2, Table1.id == Table2.sample_id)
.group_by(Table1.id)
.having(
datetime.datetime.now() > ((Table2.query.filter_by(
start=
(database.session.query(func.max(Table2.start)))
)).first().end +
datetime.timedelta(minutes=Table1.query.filter_by(
id=Table1.id
).first().frequency))).all()
此SQL查询从数据库返回一行数据,但是我在sqlalchemy中的查询返回空dict。有人可以帮我重新创建SQL查询吗?