Several aggregate functions in one query

SQL allows you including several aggregate functions in the same query. For example, we might want to receive both the lowest and the highest GPA for each group. In SQL, such a query would look like this:

  1. SELECT s.group_number, MIN(s.gpa), MAX(s.gpa)
  2. FROM Student s
  3. GROUP BY s.group_number

This query will return the lowest and the highest GPA for each group. With Pony you can use the same approach:

  1. select((s.group, min(s.gpa), max(s.gpa)) for s in Student)