21.2. SUM() Functions
This function works only with numeric values. You should also consult your particular product’s manuals to find out the precision of the results for exact and approximate numeric data types.
SUM([ALL] <value expression>) returns the numeric total of all known values. The NULLs are removed before the summation takes place. An empty set returns an empty result set, not a zero. If there are other columns in the SELECT list, then that empty set will be converted into a NULL.
SUM(DISTINCT <value expression>) returns the numeric total of all known, unique values. The NULLs and all redundant duplicates were removed before the summation took place. Again, an empty set returns an empty result set, not a zero.
That last rule is hard ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access