开发者

SQLAlchemy subquery - average of sums

is there any way how to write the following SQL statement in SQLAlchemy ORM:

SELECT AVG(a1) FROM (SELECT s开发者_如何学编程um(irterm.n) AS a1 FROM irterm GROUP BY irterm.item_id);

Thank you


sums = session.query(func.sum(Irterm.n).label('a1')).group_by(Irterm.item_id).subquery()
average = session.query(func.avg(sums.c.a1)).scalar()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜