I had created model donation to save donation information and now i want to display total amount of donation to be shown with all the other field

my table is as follows

--------------------------- name address phone amount test abc 454545 55 test2 pqr 83294 10 test abc 31286 50 and desires output would be like

--------------------------- name address phone amount test abc 454545 105 test2 pqr 83294 10

i'm trying to put code

$testmodel = Mage::getModel('donation/donation') ->getCollection() ->getSelect()->group('name') ->addExpressionAttributeToSelect('SUM({{amount}})', 'amount');

but it can't work.


I just used this query to get desired output

$resource = Mage::getSingleton('core/resource');
$read = $resource->getConnection('core_read');
$select = $read->select()->from(array('cp'=>$categoryProductTable),array('sum(amount) as sum', 'name', 'address' ,'phone'));

The method addExpressionAttributeToSelect is only available as a method for the resource model. Since you've appended it after getSelect it wont be able to find the method.

$testmodel = Mage::getModel('donation/donation')->getCollection()
   ->addExpressionAttributeToSelect('SUM(`amount`)', 'amount')

Try above, that should work better

  • it didn't work I have to perform it using Zend Query Oct 14 '15 at 10:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.