MySQL SQLLesson 21Free preview
MySQL SUM()
This lesson is part of MySQL · All levels
Summary
The SUM() function sums all the numerical values in a column, e.g. total sales or total points. Because it only works on numbers, the SUM() on the text column will produce either 0 or error depending on the content, so make sure the column is numeric in type. Like other aggregate functions, SUM() ignores the value of NULL and can be combined with GROUP BY or WHERE.
Key points
- SUM() sums the values of the numerical column in the row group
- The value of NULL is passed, not counted as zero
- Can be used with WHERE to sum the filtered lines
- Together with GROUP BY, SUM() yields a total per group
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.