使用连接订单表获取集合中客户的最后订单ID

时间:2013-07-29 01:07:11

标签: mysql magento zend-db

这就是我所拥有的,但它获得了第一个订单ID

/**      
 * @param string, datetime UTC
 * @param string, datetime UTC
 * @return Mage_Customer_Model_Resource_Customer_Collection         
 */
public function filterOrderId($from, $to) 
{
    $this->addAttributeToSelect(array('first_name', 'last_name', 'gender', 'dob'));
    $this->joinTable(
        array('o' => 'sales/order_grid'), 
        'customer_id=entity_id', 
        array(
            'order_id'                => 'increment_id',
            'grand_total'             => 'grand_total'
        ),
        array(                
            'created_at'              => array('from'=>$from,'to'=>$to),
            'status'                  => array("nin"=>array('canceled', 'rejected', 'closed', 'complete'))
        ),                     
        'inner'  
    );

    $this->getSelect()->group('o.customer_id');
    //$this->addExpressionAttributeToSelect('max_id', 'MAX({{entity_id}})', 'entity_id'); //this does not work
    //$this->setOrder('max_id', 'desc');

    return $this;
}

我想我需要在连接中添加子查询,但我不知道该怎么做。

0 个答案:

没有答案