SUM(expression)

Description: Returns the sum of expression. Generally used with GROUP BY clause, but otherwise operates on all rows returned.

If the set has no rows, it returns NULL.

Example:

SELECT city_name, SUM(temperature)
  FROM weather
  GROUP BY city_name

returns the minimum temperature recorded for each city in table weather.

Get Sams Teach Yourself MySQL in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.