我想在共享相同标签的连续行中求和。有任何非常简单的方法吗?
示例:我从这张表开始......
qty flag
1 OFF
3 ON
2 ON
2 OFF
9 OFF
4 ON
...并想生成......
qty flag
1 OFF
5 ON
11 OFF
4 ON
答案 0 :(得分:3)
一种方法:
q)show t:flip`qty`flag!(1 3 2 2 9 4;`OFF`ON`ON`OFF`OFF`ON)
qty flag
--------
1 OFF
3 ON
2 ON
2 OFF
9 OFF
4 ON
q)show result:select sum qty by d:sums differ flag,flag from t
d flag1| qty
----------| ---
1 OFF | 1
2 ON | 5
3 OFF | 11
4 ON | 4
然后以您需要的格式获取它:
q)`qty`flag#0!result
qty flag
--------
1 OFF
5 ON
11 OFF
4 ON