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:
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:
SELECT COUNT(CustomerID), Country FROM Customers GROUP BY Country ORDER BY COUNT(CustomerID) DESC; |