[英]SQLAlchemy: get the object with the most recent date
How do I query a table for the object with the most recent table?如何在表中查询具有最新表的对象?
I've got a table which holds我有一张桌子
class Ticker(Base):
updated = Column('updated', DATETIME, index=False, nullable=False,primary_key=True)
high = Column('high', FLOAT, index=False, nullable=False)
I'm trying to find out how I can get the object with the most recent updated field?我正在尝试找出如何获取具有最新更新字段的对象? Currently I'm doing the following:
目前我正在做以下事情:
maxdate = db_session.query(func.max(Ticker.updated)).first()[0]
Ticker.query.filter(Ticker.updated == maxdate).first()
I was wondering if there is a more efficient/shorter way to do this?我想知道是否有更有效/更短的方法来做到这一点?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.