How to use avg and sum in SQLAlchemy query

You should use something like:

from sqlalchemy.sql import func
session.query(func.avg(Rating.field2).label('average')).filter(Rating.url==url_string.netloc)

You cannot use MyObject.query here, because SqlAlchemy tries to find a field to put result of avg function to, and it fails.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)