Sorting in the Same Category

Example

The Excel file book1.xlsx is the students math score table, and some of the data is shown in the figure below:

..

The task is to group the scores by class, each class is sorted in one row, and the students' names are sorted in order from the highest math score to lowest one, as shown in the following figure:

..

Write SPL script:


A

1

=T("E:/work/book1.xlsx")

2

=A1.group(Class).(~.Class|~.sort(Maths:-1).(Name))

3

=file("E:/work/book2.xlsx").xlsexport@w(A2)

A1 Read the data of book1.xlsx

 

A2 Group the data by class, loop through each group, sort the records in the group in reverse order according to Maths, and merge the class number and the sorted name into a sequence

 

A3 Store A2 to book2.xlsx, and the @w option indicates that the A2 to be stored is a sequence of sequences