接收一个或多个数组。Receives one or more arrays. 按降序对第一个数组进行排序。Sorts the first array in descending order. 对其余数组进行排序,以匹配重新排序后的第一个数组。Orders the remaining arrays to match the reordered first array.


array_sort_desc(array1[, ..., argumentN]) array_sort_desc(array1 [, ..., argumentN ])

array_sort_desc(array1[, ..., argumentN],nulls_last) array_sort_desc(array1 [, ..., argumentN ],nulls_last)

如果未提供 nulls_last,则使用默认值 trueIf nulls_last isn't provided, a default value of true is used.


  • array1...arrayN:输入数组。array1...arrayN : Input arrays.
  • nulls_last:一个布尔值,指示 null 是否应位于最后nulls_last : A bool indicating whether nulls should be last


返回与输入中相同数量的数组,第一个数组按升序排序,然后对其余数组排序,以匹配重新排序后的第一个数组。Returns the same number of arrays as in the input, with the first array sorted in ascending order, and the remaining arrays ordered to match the reordered first array.

对于与第一个数组长度不同的所有数组,均返回 nullnull will be returned for every array that differs in length from the first one.

如果数组包含不同类型的元素,则按以下顺序对其进行排序:If an array contains elements of different types, it will be sorted in the following order:

  • 数值、datetimetimespan 元素Numeric, datetime, and timespan elements
  • 字符串元素String elements
  • GUID 元素Guid elements
  • 其他所有元素All other elements

示例 1 - 对两个数组进行排序Example 1 - Sorting two arrays

let array1 = dynamic([1,3,4,5,2]);
let array2 = dynamic(["a","b","c","d","e"]);
print array_sort_desc(array1,array2)
array1_sorted array2_sorted
[5,4,3,2,1][5,4,3,2,1] ["d","c","b","e","a"]["d","c","b","e","a"]


输出列名称根据函数的参数自动生成。The output column names are generated automatically, based on the arguments to the function. 若要为输出列分配不同的名称,请使用以下语法:... | extend (out1, out2) = array_sort_desc(array1,array2)To assign different names to the output columns, use the following syntax: ... | extend (out1, out2) = array_sort_desc(array1,array2)

示例 2 - 对子字符串进行排序Example 2 - Sorting substrings

let Names = "John,Paul,George,Ringo";
let SortedNames = strcat_array(array_sort_desc(split(Names, ",")), ",");
print result = SortedNames

示例 3 - 合并 summarize 和 array_sort_ascExample 3 - Combining summarize and array_sort_desc

datatable(command:string, command_time:datetime, user_id:string)
    'chmod',   datetime(2019-07-15),   "user1",
    'ls',      datetime(2019-07-02),   "user1",
    'dir',     datetime(2019-07-22),   "user1",
    'mkdir',   datetime(2019-07-14),   "user1",
    'rm',      datetime(2019-07-27),   "user1",
    'pwd',     datetime(2019-07-25),   "user1",
    'rm',      datetime(2019-07-23),   "user2",
    'pwd',     datetime(2019-07-25),   "user2",
| summarize timestamps = make_list(command_time), commands = make_list(command) by user_id
| project user_id, commands_in_chronological_order = array_sort_desc(timestamps, commands)[1]
user_id commands_in_chronological_order
user1user1 [[
user2user2 [[


如果数据可能包含 null 值,请使用 make_list_with_nulls,而不是 make_listIf your data may contain null values, use make_list_with_nulls instead of make_list.

示例 4 - 控制 null 值的位置Example 4 - Controlling location of null values

默认情况下,null 值放在已排序数组的最后。By default, null values are put last in the sorted array. 但是,你可以显式控制它,方法是将 bool 值添加为 array_sort_desc() 的最后一个参数。However, you can control it explicitly by adding a bool value as the last argument to array_sort_desc().

具有默认行为的示例:Example with default behavior:

print array_sort_desc(dynamic([null,"blue","yellow","green",null]))

具有非默认行为的示例:Example with non-default behavior:

print array_sort_desc(dynamic([null,"blue","yellow","green",null]), false)

请参阅See also

若要按升序对第一个数组排序,请使用 array_sort_asc()To sort the first array in ascending order, use array_sort_asc().