database design – In dolphindb, how to take the average of the top 5% records in a table

For example, sort by the trademoney,then take the average, minimum and standard deviation of the top 5%. like each stock is calculated by group, now i got SecurityID and TradeMoney of each stock,and 5day level 2 data, which is about 30 million.

how to take the average of top 5% records in this table.