英文:
How to make the results of segmentby displayed for only the last row in each segment?
问题
我已经使用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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论