对于 SQLAlchemy的
,谁可以轻轻地得到的简单的例子SQL
类似功能sum
,average
,min
,max
,对于一个柱(score
在作为示例的以下)。
至于这个映射器:
class Score(Base):
#...
name = Column(String)
score= Column(Integer)
#...
有关用法,请参见《SQL表达式语言教程》。下面的代码显示用法:
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