Do you have the option of doing this is some server-side language? Or even in an executable application?
Examples:
In Java, as a standalone.
In PHP.
In ASP.
Whatever?
I think that would be far be easier than trying to get this right in a SQL query.
Oh, and what kind of DB is this??? SQL Server? Oracle? MySQL? What?
I am *assuming* that when you show us records such as
Code:
CDC90050 | A | SCM70001 | 8 | 0 | 0 | R | 32
CDC90050 | A | SCM70001 | 8 | 8 | 0 | R | 1
CDC90050 | A | SCM70001 | 8 | 16 | 0 | R | 1
CDC90050 | A | SCM70001 | 8 | 24 | 0 | R | 9
CDC90050 | A | SCM70001 | 16 | 32 | 0 | R | 9C5
That you intend that the "groups" are based on the
Code:
CDC90050 | A | SCM70001 |
part in each record. But then how are the records then *ordered*???
Excepting for the first two records you showed, it looks like they are ordered by the last field (1,9,9C5,9C6,etc.), but those first two records (32 and then a second 1) toss that out of the possibilities.
You just aren't giving enough details.
And you say that these records are coming via a query on other tables? So why aren't you doing the summations as part of *that* query?
Very very lost, still.