1.11 Top/Bottom N: getting ordinal numbers of records

 

Find ordinal numbers of records of students whose scores rank in top 2 based on the following Scores table.

STUDENTID SCORE
1 84
2 77
3 69
4 81
5 80

SPL script:

A
1 =connect(“db”)
2 =A1.query@x(“select * from Scores”)
3 =A2.ptop(-2, SCORE)

A1 Connect to the database;
A2 Query students’ scores;
A3 Get ordinal numbers of records of students whose scores rank in top 2.

Execution result:

105
33