說,如果有一個與領域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
?