July 2010
Intermediate to advanced
840 pages
16h 33m
English
While this topic is a bit more mathematical than most SQL programmers actually have to use in their work, it does demonstrate the power of SQL and a little knowledge of some basic college math.
The summation of a series builds a running total of the values in a table and shows the cumulative total for each value in the series. Let’s create a table and some sample data.
CREATE TABLE Series (seq_nbr INTEGER NOT NULL PRIMARY KEY, val INTEGER NOT NULL, answer INTEGER -- null means not computed yet ); Sequences seq_nbr val answer ======================= 1 6 6 2 41 47 3 12 59 4 51 110 5 21 131 6 70 201 7 79 280 8 62 342 ...
This simple summation is not a problem.
UPDATE Series SET answer = (SELECT SUM(R1.val) FROM Series ...
Read now
Unlock full access