Aggregate Functions
Aggregates are functions you can use to get summary values. You apply aggregates to sets of rows: to all the rows in a table, to just those rows specified by a WHERE clause, or to groups of rows set up in the GROUP BY clause (discussed in the next chapter). No matter how you structure the sets, you get a single value for each set of rows.
Take a look at the difference in the results of the following two queries: The first finds each individual yearly sale value in the titles table (one sale listing per row); the second calculates the total yearly sales for all books in the titles table (one total sale listing per set, and the table is the set).
SQL
select ytd_sales from titles ytd_sales =========== 4095 4095 3336 4072 3876 ...
Get Practical SQL Handbook, The: Using SQL Variants, Fourth 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.