Aggregate functions often need an added GROUP BY statement.
The GROUP BY Statement
The GROUP BY statement is used in conjunction with the aggregate functions to group the result-set by one or more columns.
SQL GROUP BY Syntax
WHERE column_name operator value
GROUP BY column_name;
SQL GROUP BY Example
Now we want to find the number of orders sent by each shipper.
The following SQL statement counts as orders grouped by shippers:
LEFT JOIN Shippers
GROUP BY ShipperName;