The Arcade docs have examples for the GroupBy() function:
Returns the count and the average height of each tree type
var treeStats = GroupBy($layer,
[ // fields/expressions to group statistics by
{ name: 'Type', expression: 'TreeType'},
{ name: 'Status', expression: 'TreeStatus'}
],
[ // statistics to return for each unique category
{ name: 'Total', expression: '1', statistic: 'COUNT' },
{ name: 'AvgHeight', expression: 'Height', statistic: 'AVG' },
{ name: 'MaxPercentCoverage', expression: 'CoverageRatio * 100', statistic: 'MAX' }
]
);
// treeStats contains features with columns Type, Status, Total, AvgHeight, MaxPercentCoverage
// Each unique tree type (combination of type and status) will have a count, average height, and maximum value of percent coverage
That GroupBy() stuff can get messy in a hurry. It would help if we could see what the SQL would look like, right in the docs.
(possibly as a comment in the Arcade code example)