title: Magento custom reports: Get data from database
body: <p>I need some help.</p>
  
  <p>I created a custom report in Magento.
  Now I want to list all products wich have been ordered in a month in my grid.
  In my report are the following columns: SKU, Name, Ordered Quantity and Base Cost.</p>
  
  <p>In the column "Ordered Quantity" I want to show how often a product has been ordered.
  In the column "Base Cost" I want to show the total base costs (ordered quantity * base cost).</p>
  
  <p>With the following code I get so correct product names and skus.
  The other columns are not correct.</p>
  
  <p>Can someone help me?</p>
  
  <pre><code>$this-&gt;getSelect()-&gt;reset()
          -&gt;from(
              array('order_items' =&gt; $this-&gt;getTable('sales/order_item')),
              array(
                  'ordered_qty' =&gt; 'SUM(order_items.qty_ordered)',
                  'order_items_name' =&gt; 'order_items.name',
                  'base_cost' =&gt; 'SUM(order_items.base_cost)',
                  'sku' =&gt; 'order_items.sku'
              ))
          -&gt;where("created_at BETWEEN '".$from."' AND '".$to."'")
          -&gt;where('parent_item_id IS NULL')
          -&gt;group('order_items.product_id')
          -&gt;having('SUM(order_items.qty_ordered) &gt; ?', 0)
          -&gt;order(
              array(
                  'SUM(order_items.qty_ordered) DESC'
              ));
  </code></pre>