Understanding Data Grouping

In the last lesson, you learned that the SQL aggregate functions can be used to summarize data. This enables you to count rows, calculate sums and averages, and obtain high and low values without having to retrieve all the data.

All the calculations thus far were performed on all the data in a table or on data that matched a specific WHERE clause. As a reminder, the following example returns the number of products offered by vendor DLL01:

SELECT COUNT(*) AS num_prods
FROM Products
WHERE vend_id = `dll01';
num_prods
-----------
4

But what if you wanted to return the number of products offered by each vendor? Or products offered by vendors who offer a single product or only those who offer more than ten products? ...

Get Sams Teach Yourself SQL in 10 Minutes 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.