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 - 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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
Getting started with aggregate functions6m 59s
-
(Locked)
Making aggregate functions work for you5m 35s
-
(Locked)
Group data using GROUP BY6m 26s
-
(Locked)
Filter on groups of data with HAVING4m 36s
-
(Locked)
Challenge: Practice with aggregate functions1m 38s
-
(Locked)
Solution: Aggregate functions solved5m 6s
-
-
-
-