Introduction to SQL Group By with Count
In this step by step SQL tutorial I will show you how to use Group by clause witch count aggregate function. For the purpose of this tutorial I will use SQL Server 2008 R2.
Prior knowledge: It might be easier for you to follow this tutorial if you have knowledge of Group By clause
for more information visit SQL Group By tutorial
SQL Group By Count Rows
In our example we will use DimCustomer table which contains 18494 rows.
Let's check what we have in our table that we can Group and count. Gender seems to be a good choice.
What we want to see is total customers grouped by Gender.
In our SQL statement I will put Gender field in Group By clause and in select, additionally I will put COUNT(*) as TotalGender that will perform count on the group value. See below code and results.
Our results shows that there are approximately the same amount both Female and Male customers and we were able to find out that by using Group by and Count function.
NEXT EXAMPLE: I will try to put more example with count aggregate function soon.
Good luck with your SQL Group by count queries