Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8368457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:23:40+00:00 2026-06-09T13:23:40+00:00

I can do this with regular mySQL but I would like to be able

  • 0

I can do this with regular mySQL but I would like to be able to do it “the magento way” as it were…

What I would like to do, is run a query which will SUM(grand_total) for my order totals between set dates, ie work out the total revenue from July 2012.

I’ve tried various variations on this, and I might be really close or I might be a million miles away, so I’d appreciate any help anyone can give me! What I have so far is:

$orders = Mage::getModel('sales/order')->getCollection();

$orders->addAttributeToFilter('date_field', array(
'from' => '2011-09-01',
'to' => '2011-09-30',
));
$orders->addExpressionAttributeToSelect('grand_total', 'SUM({{grand_total}})', grand_total);
$orders_total->getSelect()->$orders->grand_total(SUM(grand_total));

Thank you in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:23:41+00:00Added an answer on June 9, 2026 at 1:23 pm

    ‘the magento way’ would be using collections.

    Your question states all orders since July? If this is the case then you only require the ‘from’ in the filter and not the ‘to’…

    $orderTotals = Mage::getModel('sales/order')->getCollection()
        ->addAttributeToFilter('status', Mage_Sales_Model_Order::STATE_COMPLETE)
        ->addAttributeToFilter('created_at', array('from'  => '2012-07-01'))
        ->addAttributeToSelect('grand_total')
        ->getColumnValues('grand_total')
    ;
    $totalSum = array_sum($orderTotals);
    
    // If you need the value formatted as a price...
    $totalSum = Mage::helper('core')->currency($totalSum, true, false);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In MySQL, I would like to do a select and get a sum, but
I am new to doing this sort of thing but I would like to
How can I update this regular expression to find and replace not just /news/
Can someone explain this to me. I am pretty good with perl regular expressions
Can anyone please help me with this...I'm not very good with regular expressions and
Who can help me to translate this XML Schema pattern [0-9]+-([0-9]|K) to java regular
I'm new to regular expression and just can't seem to figure this out: '/^[A-Za-z0-9](?:.[A-Za-z0-9]+)$/'
I'm not a regular C++er, so this question might be fairly trivial: Can anybody
Can this MS-Access query be improved? i.e. the SELECT TOP 1 col FROM Table2
Can this be done? It seems like this should be possible. In general, I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.