• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Running Sums

The computation of running sums is a common operation. To illustrate, consider Table 19-1, which contains the duration (in hours, say) for various events.

Table 19-1. A running sum

Event

Duration

1

1

2

5

3

6

4

3

5

4

6

1

7

8

8

2

For each event, we want to compute the sum of all the durations of the events that precede that event. This sum is a running sum.

Solution

One approach is to use the Cartesian product of the table with itself. In this way, we can access all records whose Event number precedes that of a given record. For instance, for the record with Event number 5, we need access to the records with Event numbers 1 through 4. The Cartesian product provides us with these records.


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint