Locked lesson.
About this lesson
We will look at how we can sort returned data using the GROUP_BY clause
Exercise files
Download this lesson’s related exercise files.
GROUP BY Clause.docx58.8 KB GROUP BY Clause - Solution.docx
59 KB
Quick reference
GROUP BY Clause
"Group By" allows us to group similar results together.
When to use
Use it when you want to group similar results together.
Instructions
The Group By Clause looks like this:
SELECT COUNT ([Country]), [Country]
FROM [Customer].[dbo].[Current_Customers]
GROUP BY [Country]
This will give us a column with the number of customers from each country, and a corresponding column to show which country they are from. For example:
1 Canada
5 USA
3 Switzerland
Hints & tips
- Group by allows you to aggregate and group
Lesson notes are only available for subscribers.