'유형', '다양성'및 '가격'속성이있는 테이블이있는 경우, 여기에 각 유형의 최소 가격으로 레코드를 가져 오는 오래된 질문입니다. 입니다. 이보다 더 나은 구현이 있습니까ActiveRecord의 각 그룹에 대한 최소/최대 가져 오기
minprices = Table.minimum(:price, :group => type)
result = []
minprices.each_pair do |t, p|
result << Table.find(:first, :conditions => ["type = ? and price = ?", t, p])
end
: 우리는 아마도하여이 모방 할 수
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에서
, 우리는에 의해 this을 할 수 있습니까?
:
여기업데이트 된 URL입니다