SQLAlchemy-WHERe子句中的子查询

SQLAlchemy-WHERe子句中的子查询,第1张

SQLAlchemy-WHERe子句中的子查询

这应该可以工作(不同的SQL,结果相同):

t = Session.query(    Posts.user_id,    func.max(Posts.post_time).label('max_post_time'),).group_by(Posts.user_id).subquery('t')query = Session.query(User, Posts).filter(and_(    User.user_id == Posts.user_id,    User.user_id == t.c.user_id,    Posts.post_time == t.c.max_post_time,))for user, post in query:    print user.user_id, post.post_id

其中c代表“列”



欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5647262.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存