9

Summarizing Data

Keywords Introduced

DISTINCT • SUM • AVG • MIN • MAX • COUNT • GROUP BY • HAVING • ROW_NUMBER • OVER • RANK • DENSE_RANK • NTILE • PARTITION BY • PERCENT_RANK • PERCENTILE_CONT • WITHIN GROUP • LAG

Up until now, all the calculations, functions, and CASE expressions we’ve used have only altered the values of individual columns. More significantly, the rows we’ve retrieved have corresponded to rows in tables in the underlying database. Now we 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 ...

Get The Language of SQL, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.