Implement min_by aggregation function