Description

The SQL keyword GROUP BY is used to group records of a result set.

The below SQL returns the number of customers by country.

SELECT country, COUNT(*)
FROM customers
GROUP BY country;

The below SQL returns the number of orders by date, with results sorted by order date in descending order.

SELECT order_date, COUNT(*)
FROM orders
GROUP BY order_date
ORDER BY order_date DESC;

Related Links