これは私が持っているものですが、最初の注文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;
}
結合にサブクエリを追加する必要があると思いますが、その方法がわかりません。