小编典典

SQLAlchemy按降序排列?

python

如何descending在如下所示的SQLAlchemy查询中使用ORDER BY ?

此查询有效,但以升序返回:

query = (model.Session.query(model.Entry)
        .join(model.ClassificationItem)
        .join(model.EnumerationValue)
        .filter_by(id=c.row.id)
        .order_by(model.Entry.amount) # This row :)
        )

如果我尝试:

.order_by(desc(model.Entry.amount))

然后我得到:NameError: global name 'desc' is not defined


阅读 217

收藏
2020-12-20

共1个答案

小编典典

from sqlalchemy import desc
someselect.order_by(desc(table1.mycol))

来自@
jpmc26的用法

2020-12-20