English | 简体中文

api-docs / org.ktorm.entity / eachAverageByTo

eachAverageByTo

inline fun <E : Any, T : BaseTable<E>, K : Any, M : MutableMap<in K?, in Double?>> EntityGrouping<E, T, K>.eachAverageByTo(
    destination: M,
    columnSelector: (T) -> ColumnDeclaring<out Number>
): M
(source code)

Group elements from the source sequence by key and average the columns or expressions provided by the
columnSelector function for elements in each group, then store the results in the destination map.

The key for each group is provided by the EntityGrouping.keySelector function, and the generated SQL is like:
select key, avg(column) from source group by key.

Parameters

destination - a MutableMap used to store the results.

columnSelector - a function that accepts the source table and returns the column or expression for averaging.

Return
the destination map associating the key of each group with the averaging result in the group.