4.13 Rank row-wise data by a single field

 

Rank records in the following score table by Math score:

Class Name Math
1 Tom 85
2 John 92
2 Joan 86
1 Rocky 95
2 Ham 92
1 Kate 83
1 Rose 95
2 Nomy 78
1 Neil 91
2 Jack 84
1 Joe 98

SPL script:

A
1 =T(“score.xlsx”)
2 =A1.(Math)
3 =A1.derive(A2.rank@z(Math):Rank)

A1 Import data from the table.
A2 Get values in Math field.
A3 Add a Rank field to A1 and calculate rank of the current math score using A2’s expression.

Execution result:

Class Name Math Rank
1 Tom 85 8
2 John 92 4
2 Joan 86 7
1 Rocky 95 2
2 Ham 92 4
1 Kate 83 10
1 Rose 95 2
2 Nomy 78 11
1 Neil 91 6
2 Jack 84 9
1 Joe 98 1