Database Reference
In-Depth Information
SUM
SUM finds the total value by adding together a set of numeric values. To add up all of the
scores that our visitors gave our website we would use:
SELECT SUM(score)
FROM
visitorbook
The results are shown in Figure 10.9.
Using Multiple Aggregates
You are not limited to just using one aggregate in a query. For instance, if we wanted to cal-
culate the average score given by a visitor, we can use an aggregate to sum the score divided
by a count of the scores given, as follows:
SELECT
SUM(score) / COUNT(score) AS average
FROM
visitorbook
Have a look at Figure 10.10 to see the average score for our site based on the data that was
in the tables.
Figure 10.9 The sum of the scores on the visitorbook.
Figure 10.10
The average of the scores on the visitorbook.
Search WWH ::




Custom Search