DEV Community

Judy
Judy

Posted on

Getting the record containing the maximum value of a specified field #eg57

Get the record containing the maximum value of a specified field, such as finding the nation that holds the first place on the Olympic Medal Table for the longest time.

Image description
maxp() function is used to get the record containing the maximum value.
SPL script:

Image description
A1 Retrieve the Olympic medal count table;
A2 Sort A1’s table by game and total medal count in descending order;
A3 Get one record, which is the first one of the ordered records, from each game;
A4 Group A3’s records by nation;
A5 Get the longest group, which has the nation occupying the first place for the longest time.

Execution result:

Image description

SPL open source address

Download

Top comments (0)