From the course: Programming Foundations: Databases
Unlock the full course today
Join today to access over 23,400 courses taught by industry experts.
Aggregate functions
From the course: Programming Foundations: Databases
Aggregate functions
- [Instructor] SQL offers aggregate functions which use more than one piece of data to generate a value. One of the most common aggregate functions is count, which returns the number of records in a particular field from rows that match a particular condition. This is helpful because it can be time consuming to count up records by hand. Let's see how many customers we have in our customers table. I'll write a query to do this. With select count first name from customers. And then I'll run that query. The count function takes the name of a field and tells us how many rows that match our criteria have a value in that field. Because of how the database is designed we know that there won't be any null values in the first name field. We don't allow anyone to enter a record with an empty first name. We could also use last name or even the key field to get a count of matching records. We can stack this with a search like the state…