Aggregate Functions
We are often interested in understanding the properties of an entire column or table as opposed to just seeing individual rows of data. As a simple example, let's say you were wondering how many customers ZoomZoom has. You could select all the data from the table and then see how many rows were pulled back, but it would be incredibly tedious to do so. Luckily, there are functions provided by SQL that can be used to perform calculations on large groups of rows. These functions are called aggregate functions. Aggregate functions take in one or more columns with multiple rows and return a number based on those columns. As an illustration, we can use the COUNT
function to count the total number of ZoomZoom customers by counting the total rows in the customers table:
SELECT COUNT(customer_id) FROM customers;
The COUNT
function will return the number of rows without a NULL
value in the column. Since the customer_id
column is a primary key and cannot be NULL...