From the course: SQL Essential Training
Unlock the full course today
Join today to access over 23,100 courses taught by industry experts.
Grouping by many fields - SQL Tutorial
From the course: SQL Essential Training
Grouping by many fields
- [Instructor] Let's wrap up our look at aggregate functions used in conjunction with the group by clause and take a look at one more scenario. Now it is possible to group by more than one aggregate field at a time. Let's say we wanted a more detailed breakdown of our average invoices. We could write our query so that our aggregate data is grouped first by country then by city. So let's take a look at modifying our existing SQL statement to respond to WSDA Music's latest request. And here we have it. What are the average invoice totals by billing country and city? As we have our query set up now we are responding to a grouped by billing city result. The current request also wants us to include the billing country. So let's do that. In our select we're going to also include the billing country. Let's put our comma. And now, because we now went from one non aggregated field to two, we must now include both of…
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.