1.13 Getting Top/Bottom N directly

 

With a sequence already arranged in the expected order, just get the first or last N members by their ordinal numbers.
SPL script:

A
1 =create(a,b).record([“a”,10,“b”,20,“c”,30,“d”,40,“e”,50,“f”,60])
2 =A1.ptop(-2,0)
3 =A1.ptop(2,0)
4 = A1.top(-2;0)
5 = A1.top(2;0)

A1 Create a table sequence;
A2 Return [5,6]. ptop function and top function will get the top or bottom N records directly without performing a sort when the second parameter is 0;
A3 Return [1,2];
A4 Return bottom two records;

imagepng

A5 Return top two records.

imagepng