SQLAlchemy ORDER BY DESCENDING?

前端 未结 6 1859
迷失自我
迷失自我 2020-11-27 09:21

How can I use ORDER BY descending in a SQLAlchemy query like the following?

This query works, but returns them in ascending order:



        
6条回答
  •  心在旅途
    2020-11-27 09:45

    You can try: .order_by(ClientTotal.id.desc())

    session = Session()
    auth_client_name = 'client3' 
    result_by_auth_client = session.query(ClientTotal).filter(ClientTotal.client ==
    auth_client_name).order_by(ClientTotal.id.desc()).all()
    
    for rbac in result_by_auth_client:
        print(rbac.id) 
    session.close()
    

提交回复
热议问题