sqlalchemy: get max/min/avg values from a table

The following functions are available with from sqlalchemy import func:

  • func.min
  • func.max
  • func.avg

Documentation is available here.

You can use them i.e. in the query() method.

Example:

session.query(self.stats.c.ID, func.max(self.stats.c.STA_DATE))

(just like you use aggregate functions in plain SQL)

Leave a Comment

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