From the course: SQL for Non-Programmers

Unlock the full course today

Join today to access over 23,100 courses taught by industry experts.

Group data using GROUP BY

Group data using GROUP BY - SQL Tutorial

From the course: SQL for Non-Programmers

Group data using GROUP BY

We can use aggregate functions to count rows, calculate sums and averages, or return the min and max value from a column of data. So far, we have performed these calculations over all of the data in our table, or the data that meets a certain filter condition. But what if, instead of returning a single calculation, we need calculations performed over groups of data? For example, we may need summary statistics like total sales for each product category or each employee. Grouping in SQL can be used to divide the data into groups and then perform aggregate calculations on those groups. Grouping is done using the GROUP BY clause, which must be placed after the WHERE clause and before any ORDER BY clause. Our management team has requested a report of sales performance by state. Our olive oil sales table has a column for customer state, so this is the perfect place to access the information we need. Let's move back over to SLS and jump right in. We'll start by selecting the column for…

Contents