如何使用SQLAlchemy在Postgres中执行日期查询

2024-10-04 03:22:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我似乎无法将以下查询转换为SQLAlchemy。在

我想翻译以下问题:

SELECT date_trunc('day', time), "PositionReport".callsign FROM tvh_aircraft."PositionReport" WHERE "PositionReport".reg = 'PH-BVA'
GROUP BY 1, "PositionReport".callsign

我试过以下几种方法,但没有成功。在

^{pr2}$

提前谢谢你的帮助。在


Tags: fromdatetimesqlalchemyregwhereselectph
1条回答
网友
1楼 · 发布于 2024-10-04 03:22:58
session.query(func.date_trunc('day', PositionReport.time), 
              PositionReport.callsign) \
    .filter(PositionReport.reg=='PH-BVA') \
    .group_by(func.date_trunc('day', PositionReport.time),
              PositionReport.callsign).all()

或者如果您需要GROUP BY 1

^{pr2}$

相关问题 更多 >