sqlalchemy simple example of `sum`, `average`, `min`, `max`

前端 未结 1 439
北恋
北恋 2020-12-29 20:28

For sqlalchemy, Who can gently give simple examples of SQL functions like sum, average, min, max, f

1条回答
  •  礼貌的吻别
    2020-12-29 20:56

    See SQL Expression Language Tutorial for the usage. The code below shows the usage:

    from sqlalchemy.sql import func
    qry = session.query(func.max(Score.score).label("max_score"), 
                        func.sum(Score.score).label("total_score"),
                        )
    qry = qry.group_by(Score.name)
    for _res in qry.all():
        print _res
    

    0 讨论(0)
提交回复
热议问题