Последний выбор в рельсах
Statistic.joins("inner join (select customer_id,max(created_at) as created_at from statistics group by customer_id) as stats2 on statistics.customer_id = stats2.customer_id and statistics.created_at = stats2.created_at").pluck("max(statistics.sold_items)")
Disgusted Dolphin