6.2 普通分组:按表达式

 

有数据如下:

ID Name Sales
010010001 Tom 7,588,420
010010002 John 8,953,172
010010003 Joan 6,276,185
020010004 Rocky 1,281,280
020010005 Ham 2,686,043
020010006 Kate 5,851,210
020010007 Rose 292,254
030020008 Nomy 8,216,267
030020009 Neil 5,143,192
030020010 Jack 3,206,181
030020011 Joe 5,536,126
030020012 Peter 6,176,479
040020013 Sunny 7,319,085
040020014 Tiger 2,392,104
040020015 Alice 446,324
040020016 Cindy 5,137,729
040020017 Leon 9,663,806
050030018 Lily 4,265,516
050030019 Kevin 8,447,330
050030020 Shelly 5,781,475
050030021 Panzy 1,917,614
050030022 Maggie 3,979,820
050030023 Mark 4,250,158
050030024 Aileen 8,215,770

按 ID 的前两位分组汇总,计算总销售额。

脚本:

A
1 =T(“Sales.xls”)
2 =A1.groups(left(ID,2):ID;sum(Sales):Sales)
3 =A1.group(left(ID,2):ID;~.sum(Sales):Sales)

A2 分组的同时进行聚合运算,不产生分组子集
A3 先产生分组子集,再对子集做聚合运算,结果和 A2 相同

运行结果:

ID Sales
01 22,817,777
02 10,110,787
03 28,278,245
04 24,959,048
05 36,857,683