我必须列出每个组的最后修改资源,为此我可以执行以下查询:
model.Session.query(
model.Resource, func.max(model.Resource.last_modified)
).group_by(model.Resource.resource_group_id).order_by(
model.Resource.last_modified.desc())
但是 SqlAlchemy 抱怨:
ProgrammingError: (ProgrammingError) column "resource.id" must appear in
the GROUP BY clause or be used in an aggregate function
我如何只能选择 resource_group_id 和 last_modified 列?
在 SQL 中,我想要的是:
SELECT resource_group_id, max(last_modified) AS max_1
FROM resource GROUP BY resource_group_id ORDER BY max_1 DESC