EZ

Eduzan

Learning Hub

Eduzan
Eduzan / SQL

SQL Clauses and Concepts

Computer Science / SQL tutorial chapter - Published 2025-12-12 - SQL

Definition: The GROUP BY clause is used in SQL to group rows that have the same values in specified columns into summary rows, like “summarize by” or “aggregate by”. It is often used with aggregate functions (COUNTMAXMINSUMAVG) to perform calculation on each group of data.

Example:

-- Grouping records by customer and counting the number of orders per customer
SELECT CustomerID, COUNT(OrderID) AS NumberOfOrders
FROM Orders
GROUP BY CustomerID;

Explanation: This query calculates the total number of orders for each customer by grouping the order data based on CustomerID. It helps in understanding customer behavior by analyzing the order frequency.

End of lesson.