KTHLARGEST(numeric_exp, K_numeric_exp)

Returns the Kth largest item indicated by k_numeric_exp in the population of numeric_exp.  

 

For any K supplied, there will be at most K-1 items that are larger. If you ask for K=1, then zero elements are larger; therefore you must have the largest item. If you ask for K=20, then up to 19 elements can be larger.

 

For the numeric column L with values:

1,2,3,2,5,6,7,8,9,4,2,22

 

KTHLARGEST(L, 1) /* Ask for the 1st largest element from column L */

returns 22

 

KTHLARGEST(L, 2) /* Ask for the 2nd largest element from column L */

returns 9

 

The result is the same as sorting the list (descending, ascending for KTHSMALLEST) and then picking the Kth element from the list. But it is much faster than sorting.

 

Parameters:

numeric_exp must be a number, or a numeric expression.

k_numeric_exp must be a number, or a numeric expression.