fetching minimum/maximum any organisation activerecord


this an age-old doubt where given list attributes 'type', 'variety' 'price', fetch record smallest cost any form there is.



in sql, by:



select f.type, f.variety, f.price   
from ( name type, min(price) minprice list organisation form ) x
inner join list f f.type = x.type f.price = x.minprice;`


we maybe embrace by:



minprices = table.minimum(:price, :group => type)  
result = []
minprices.each_pair |t, p|
outcome << table.find(:first, :conditions => ["type = ? cost = ?", t, p])
end


is there improved doing this?



Comments

Popular posts from this blog

list macos calm editors formula editors

how i practical urls indicate .aspx pages asp.net deployed an iis? (preferably but iis)

jaxb - xjc - reworking generated typesafe enum category members