Group and Summarize Archives

When you group and summarize SQL results, you use the GROUP BY Clause to output a row across specified column values.  It is typically used in conjunction with aggregate functions such as SUM or Count to summarize values.  In SQL, groups are unique combinations of fields.  Rather than returning every row in a table, when values are grouped, only the unique combinations are returned.

If you want to start to learn about grouping data, I would recommend first reading this article:  How to Use GROUP BY to Summarize Query Results

Once you understand how to group and summarize data, I would recommend reading the following:

These article will help you understand the subtle, yet important differences between these commands.

All the examples for this lesson are based on Microsoft SQL Server Management Studio and the sample databases AdventureWorks and WideWorldImporters.  You can get started using these free tools using my guide Getting Started Using SQL Server

Calculate a Running Total in SQL with Joins or Window Functions

There are several ways to calculate a running total in SQL.  In this article, we will cover two methods:  Joins, and Window Functions. We’ll first look at how to calculate the running total using an INNER JOIN.  By doing so, you’ll not only learn more about join conditions, but see how to take the result […]

Continue reading
3

What is the difference between WHERE and HAVING clauses?

In this article learn when to use WHERE and HAVING.  Both perform similar functions, but for different purposes! All the examples for this article are based on Microsoft SQL Server Management Studio and the AdventureWorks2012 database.  You can get started using these free tools using my Guide Getting Started Using SQL Server. How do Where and Having Differ? […]

Continue reading
2

What is the Difference between ORDER and GROUP BY?

Differences in Order By versus Group By

The GROUP and ORDER BY clauses are both used to organize data.  Learn which is used to sort the data, and which is used for counting and summing. All the examples for this lesson are based on Microsoft SQL Server Management Studio and the AdventureWorks2012 database.  You can get started using these free tools using […]

Continue reading
4

How to Use GROUP BY to Summarize Query Results

Group and Summarize Data

In today’s lesson you’re going to learn about grouping results returned from your queries using the GROUP BY clause. The objectives of today’s lesson are to: Learn how to group results using GROUP BY Use aggregate functions to perform calculations Understand how to filter groups using the HAVING clause Important! Please follow along and do the […]

Continue reading