Page 1 of 1

Aggregating Data

Posted: Thu Feb 04, 2010 2:32 pm
by ppp
I have 2 fields (id and name) such as

Id Name
1 abc
2 def
3 ghi
1 jkl
2 mno
3 pqr
1 stu
2 vwx
3 123
1 456
2 789
3 111

The above records should be grouped into multiple batches with max batch size 3 records. And the combination of id and batchno should be unique.
(Let's say I start my batch no.with 5 as below)
For example, my output should be as below.

Id Name BatchNo
1 abc 5
2 def 5
3 ghi 5
1 jkl 6
2 mno 6
3 pqr 6
1 stu 7
2 vwx 7
3 123 7
1 456 8
2 789 8
3 111 8

How do I achieve the batchno field result?

[/u]
    [/u]

    Posted: Thu Feb 04, 2010 3:39 pm
    by chulett
    Stage variables. Simplest answer would be a value that is incremented only when Id = 1. What happens when there are more than three ids in a 'batch'?

    Posted: Thu Feb 04, 2010 3:46 pm
    by ppp
    There will not be more than 3 id's in a batch. A batch can have less than 3 ids but not more.

    Posted: Thu Feb 04, 2010 4:08 pm
    by ray.wurlod
    Stage variables.

    Write out the logic in English, and the stage variable initialization and derivation expressions will magically appear in your brain.