4.10 Sort data in each group
We have data as follows:
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 |
The task is to group data by class and then sort data in each group by score in descending order:
SPL script:
A | |
---|---|
1 | =T(“score.xlsx”).group(Class).(~.sort@z(Math)).conj() |
Execution result:
Class | Name | Math |
---|---|---|
1 | Joe | 98 |
1 | Rocky | 95 |
1 | Rose | 95 |
1 | Neil | 91 |
1 | Tom | 85 |
1 | Kate | 83 |
2 | John | 92 |
2 | Ham | 92 |
2 | Joan | 86 |
2 | Jack | 84 |
2 | Nomy | 78 |
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProcSPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProc_SPL