# top()

Read（312） Label: get, smallest members, sequence,

Here’s how to use top() function.

## A.top()

Description:

Get the n smallest members from a sequence.

Syntax:

A.top(n,x)  Calculates expression x over each member of the sequence and return a sequence consisting of the first n smallest values of x

A.top(n;x,...)   Calculates expression x over each member of the sequence and return a sequence consisting of the first n smallest members

A.top(n,y,x)  Loop members of sequence A to compute expression x, then loop the results to compute expression y, and finally return a sequene of x’s results that correspond to the top n smallest values of y.

Note:

The function evaluates expression x with each member of the sequence A and returns the n smallest members. n must not be omitted. The omission of x is equivalent to ~.

Parameters:

 A A sequence n An integer y An expression x An expression

Options:

 @1 Return a single value if n is ±1; and null if n is 0 @2 Calculate the concatenation of all sequence-type members in sequence A and get the first n smallest members from the new sequence

Return value:

Sequence

Example:

 A 1 [a,c,e,g,f,d,b] 2 =A1.top(3,~) 3 =A1.top(3) Same as A2, when x is omitted 4 =demo.query("select * from EMPLOYEE") 5 =A4.top(10,SALARY) Get the salaries of 10 employees who are the lowest paid 6 =A4.top(10;SALARY) Get the records of 10 employees who are the lowest paid 7 [21,3,12,5] 8 =A6.top(3,~%10,~+6) [11,27,18] 9 =A7.top(-1) 10 =A7.top@1(-1) 11 =A4.top(10;SALARY,EID) Get top 10 employee records where SALARY is the lowest and EID is the smallest 12 [12,5,-6] 13 [36,1,15,9,85] 14 =[A12,A13].top@2(2) Concatenate A12 and A13 and get the first two smallest values Related functions: