Calculating a Sum with SUM()
Use the aggregate function SUM() to find the sum (total) of a set of values.
To calculate the sum of a set of values:
expr is a column name, literal, or numeric expression. The result’s data type is at least as precise as the most precise data type used in expr.
Listing 6.3 and Figure 6.3 show some queries that involve SUM(). The first query returns the total advances paid to all authors. The second query returns the total sales of books published in 2000. The third query returns the total price, sales, and revenue (= price × sales) of all books. Note a mathematical chestnut in action here: “The sum of the products doesn’t (necessarily) equal the product of the sums.”