From the course: Querying Microsoft SQL Server 2022
Unlock the full course today
Join today to access over 24,200 courses taught by industry experts.
Use GROUP BY and COUNT - SQL Server Tutorial
From the course: Querying Microsoft SQL Server 2022
Use GROUP BY and COUNT
- [Instructor] In the AdventureWorks database, there's a table called Person.Address. Let's go ahead and take a quick look at the data that it contains by running a simple SELECT statement against it. When I execute the query, you'll see that this table stores over 19,000 individual street addresses. One of the columns here is the City column, and this is the name of the city that the address is in. Here at the top, we have a whole bunch of addresses in the city of Bothell. There are potentially many addresses for each city, but if you scroll through the grid, you'll quickly see that the rows aren't in an order that makes it easy to view. We can add an ORDER BY clause into the query to help you visualize the number of addresses in each city. I'll add that onto line number three. We'll ORDER BY the city name. Now, when I execute the query again, the cities will be alphabetized so it makes it easier to see how many…
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
-
-
-
-
-
-
Understand record grouping2m 44s
-
(Locked)
Use GROUP BY and COUNT5m 6s
-
(Locked)
Aggregate functions3m 27s
-
(Locked)
Explore data with SUM7m 13s
-
(Locked)
Filter groups with HAVING3m 41s
-
(Locked)
Challenge: Obtain order summaries1m 21s
-
(Locked)
Solution: Obtain order summaries10m 34s
-
(Locked)
Solution: Group rows and aggregate data3m 45s
-
-
-
-
-
-
-