说,如果有一个与领域Ruby on Rails如何处理“按类别从产品组中选择计数(*)”?
Products
--------
ID
CategoryID
Name
Price
... etc
表Ruby on Rails的如何能给返回
select count(*) from products group by categoryID
这是显示每个类别有多少产品中的表?结果如何,而不是产品对象数组Products.find(:all)
?
随着更先进的操作,怎么样
select count(*) from products p inner join category c on p.categoryID = c.ID
group by categoryID
和
select average(price) from products p inner join category c on p.categoryID = c.ID
group by categoryID
?