如何使segmentby的结果仅显示在每个分段的最后一行?

huangapple go评论67阅读模式
英文:

How to make the results of segmentby displayed for only the last row in each segment?

问题

我已经使用segmentby按组计算总和,以第三列的值作为分段依据。上面是输出表格,在每个分段中,结果在每一行中都返回了。但我只想在每个分段的最后一行显示结果,而其他行不显示结果。我该怎么做?

英文:

如何使segmentby的结果仅显示在每个分段的最后一行?

I have used segmentby to calculate the sum by group, with the third column of values as the segment. The above is the output table and in each segment, the results are returned in every row. But I only want the result to be displayed for the last row in each segment and no result for other rows. How can I do this?

答案1

得分: 2

你可以使用isDuplicated函数通过指定keep=LAST来删除重复项,并保留最后一个重复的值。

参考以下脚本:

x = 1 2 1 2 1 2 1 2 1 2 1 2;
y = 0 0 1 1 1 2 2 1 1 3 3 2;
t = table(x, y);
select *, iif(isDuplicated(segment(y, false), LAST), NULL, sum(x)) as z from t context by segment(y, false)
英文:

You can use isDuplicated to remove duplicates and keep only the last duplicate values by specifying keep=LAST.

Refer to the following script:

x = 1 2 1 2 1 2 1 2 1 2 1 2;
y = 0 0 1 1 1 2 2 1 1 3 3 2;
t = table(x,y);
select *, iif(isDuplicated(segment(y,false),LAST),NULL,sum(x)) as z from t context by segment(y,false)

如何使segmentby的结果仅显示在每个分段的最后一行?

huangapple
  • 本文由 发表于 2023年5月18日 11:12:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/76277490.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定