GROUP BY Clause Examples

SQL statement

Description

 

SELECT Dept, Count(Dept) AS Tally
FROM Employees GROUP BY Dept;

Creates a list of unique department names and the number of employees in each of those departments

SELECT Title, Count(Title) AS Tally
FROM Employees
WHERE Dept = 'Production'
GROUP BY Title;

Calculates the number of Production department employees who have the same job title

SELECT Item, Sum(Units) AS Tally
FROM ItemsInStock
GROUP BY Item, Color;

Calculates the number of items in stock for each combination of item number and color