9. Summarizing Data

Keywords Introduced

DISTINCT  •  SUM  •  AVG  •  MIN  •  MAX  •  COUNT  •  GROUP BY  •  HAVING  •  ROW_NUMBER  •  RANK  •  DENSE RANK  •  NTILE  •  OVER  •  PARTITION BY

Up until now, all of the calculations, functions, and CASE expressions we’ve used have only altered the values of individual columns. The rows we’ve retrieved have corresponded to rows in tables in the underlying database. We now want to turn to various methods of summarizing data, by combining values in multiple rows.

The computer term usually associated with this type of endeavor is aggregation, which means “to combine into groups.” The ability to aggregate and summarize data is key to being able to move beyond a mere display of data to something approaching ...

Get The Language of SQL, Second Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.