Iterating on a set in order to reduce it
Iteration is a very natural way of thinking for us humans. We set a starting point, we step into a loop, and we end when a condition is met. While we're looping, we can do whatever we want: check, take, leave, and modify items in that set.
In this recipe, we will start from a result set as shown in the following table, and iterate through the days in each fiscal month to count the number of days for which the growth was positive. By "to reduce", we mean the filtering effect; in our example, we need to "filter out" the days for which the growth was not positive. Our goal is still to only display the fiscal months on ROWS, not the days.
Customer Count |
Growth in Customer Base | |
---|---|---|
July 2005 |
31 |
(null) |
August 2005 |
31 |
0.00% |
September 2005 |
13 |
-58.06% |
October 2005 |
27 |
107.69% |
November 2005 |
32 |
18.52% |
December 2005 |
39 |
21.88% |
Then we will look at a different approach that takes performance advantage of the block- mode calculation.
Getting ready
Start...