Combining rows
Hi,
Let's consider we have
How to convert this:
to:
Best,
Let's consider we have
- Code: Select all
EXPORT layout := RECORD
INTEGER id;
INTEGER value1;
INTEGER value2;
END;
How to convert this:
- Code: Select all
id value1 value2
1 10 5
1 20 0
2 5 10
2 5 0
2 0 15
to:
- Code: Select all
id value1 value2
1 30 5
2 10 25
Best,
- vzeufack
- Posts: 41
- Joined: Tue Sep 25, 2018 3:52 pm
vzeufack,
Either the TABLE or ROLLUP functions (both covered in the Intro to ECL Part 2 class) will do that:
HTH,
Richard
Either the TABLE or ROLLUP functions (both covered in the Intro to ECL Part 2 class) will do that:
- Code: Select all
layout := RECORD
INTEGER id;
INTEGER value1;
INTEGER value2;
END;
ds := DATASET([ {1, 10, 5},
{1, 20, 0},
{2, 5, 10},
{2, 5, 0},
{2, 0, 15}
],layout);
ROLLUP(ds,LEFT.id=RIGHT.id,
TRANSFORM(layout,
SELF.value1 := LEFT.value1 + RIGHT.value1,
SELF.value2 := LEFT.value2 + RIGHT.value2,
SELF := LEFT));
TABLE(ds,
{id,
INTEGER value1 := SUM(GROUP,ds.value1),
INTEGER value2 := SUM(GROUP,ds.value2)},
id);
HTH,
Richard
- rtaylor
- Community Advisory Board Member
- Posts: 1619
- Joined: Wed Oct 26, 2011 7:40 pm
Hi,
There are now YouTube Videos on ROLLUP:
https://www.youtube.com/watch?v=LE5HDegz5II&t=65s
https://www.youtube.com/watch?v=E-R138uuR3M
These might help.
Allan
There are now YouTube Videos on ROLLUP:
https://www.youtube.com/watch?v=LE5HDegz5II&t=65s
https://www.youtube.com/watch?v=E-R138uuR3M
These might help.
Allan
- Allan
- Posts: 444
- Joined: Sat Oct 01, 2011 7:26 pm
4 posts
• Page 1 of 1
Who is online
Users browsing this forum: No registered users and 1 guest