Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

GROUP BY

GROUP BY

The GROUP BY clause is utilized to group the result set, often in conjunction with aggregate functions like COUNT, MAX, MIN, SUM, and AVG.

The subsequent SQL enumerates the count of customers in each country:

Example

SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country;

The following SQL displays the count of customers in each country, sorted from highest to lowest:

Example

SELECT COUNT(CustomerID), Country
FROM Customers
GROUP BY Country
ORDER BY COUNT(CustomerID) DESC;