`sum`、`average`、`min`、`max`的sqlalchemy简单示例 [英] sqlalchemy simple example of `sum`, `average`, `min`, `max`
本文介绍了`sum`、`average`、`min`、`max`的sqlalchemy简单示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
对于sqlalchemy,谁能轻轻举出sum
、average
、等
、SQL
函数的简单例子>minmax
,为一列(以下以score
为例).
For sqlalchemy, Who can gently give simple examples of SQL
functions like sum
, average
, min
, max
, for a column (score
in the following as an example).
至于这个映射器:
class Score(Base):
#...
name = Column(String)
score= Column(Integer)
#...
推荐答案
参见 SQL表达式语言教程的用法.下面的代码显示了用法:
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
这篇关于`sum`、`average`、`min`、`max`的sqlalchemy简单示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文