Bu özellik, 'type', 'variety' ve 'price' niteliklerine sahip bir tablo verildiğinde, kaydı her bir tür için minimum fiyatla getirdiğiniz bir asıl sorudur. olduğunu. bundan daha iyi bir uygulama var mıActiveRecord'daki her grup için Minimum/Maksimum Getirme
minprices = Table.minimum(:price, :group => type)
result = []
minprices.each_pair do |t, p|
result << Table.find(:first, :conditions => ["type = ? and price = ?", t, p])
end
: Biz belki bu taklit olabilir
select f.type, f.variety, f.price
from ( select type, min(price) as minprice from table group by type) as x
inner join table as f on f.type = x.type and f.price = x.minprice;`
: SQL
, biz tarafından this yapabiliriz?
:
İştegüncellenmiş URL