我的 table 是这样的,我的收藏是 $testmodel=Mage::getModel(test/p1)->getCollection();
my database table is below.
id cat_id rate p_id
1 1 4 1
2 1 2 1
3 1 3 2
4 2 5 3
5 2 3 1
我想在 magento 中使用集合输出这样的输出
cat_id rate count_category
1 9 3
2 8 2
最佳答案
我发现我的问题正确代码如下
$testmodel = Mage::getModel('test/p1')
->getCollection()
->addFieldToSelect('rate')
->addFieldToSelect('cat_id');
$testmodel ->getSelect()
->columns('SUM(rate) as total,COUNT(*) AS countCategory')
->group('cat_id');
关于magento - 如何在magento中使用group by集合对列值求和(使用MAGENTO标准),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25389145/