When Poko wants to group_by with Poko.date as a Model and sum the pv column
from sqlalchemy import func
q = session.query(Poko.date, func.sum(Poko.pv)).group_by(Poko.date)
so
for date, sum_pv in q:
print date, sum_pv
Can be used with tuples like
where when you want to
q = session.query(Poko.id, Poko.date, func.sum(Poko.pv)).filter_by(id=1).group_by(Poko.date)
like
When you want to group_by with multiple
q = session.query(Poko.id, Poko.date, func.sum(Poko.pv)).group_by(Poko.date, Poko.id)
And
Recommended Posts