/** * * @return Zend_Db_Select */ protected function _prepareQuery(Mzax_Emarketing_Db_Select $query) { $conditions = $this->_getConditions(); $aggregator = $this->getDataSetDefault('aggregator', self::DEFAULT_AGGREGATOR); $expectation = $this->getDataSetDefault('expectation', self::DEFAULT_EXPECTATION); $select = $this->_combineConditions($conditions, $aggregator, $expectation); $query->joinSelect(array('goal_id' => '{order_id}'), $select, 'recipients'); $query->group(); $query->provide('recipient_id', new Zend_Db_Expr('MAX(`recipients`.`id`)')); }