Functions that return a single value from a bag of tuples:

  • AVG()
  • COUNT()
  • SUM()
  • MAX()
  • MIN()
    Non-aggregated values in SELECT output clause must appear in GROUP BY clause.
SELECT AVG(s.gpa), e.cid 
FROM enrolled AS e, student AS s 
WHERE e.sid = s.sid 
GROUP BY e.cid;


Used in collaboration with aggregate functions like COUNT(), SUM(), AVG(), MAX(), or MIN(). It arranges the result set into groups based on the values of specified columns.

If you’re going to do any grouping / aggregation at all, then you must only SELECT grouped / aggregated columns.

Multiple Group By: Need multiple columns to be the same.


Like WHERE but for GROUP BY