0

得到这个代码(在:app/code/local/Mage/Adminhtml/Block/Sales/Order/Grid.php):

protected function _prepareCollection()
    {
        $collection = Mage::getResourceModel($this->_getCollectionClass());
        $collection->getSelect()->join('sales_flat_order_item', '`sales_flat_order_item`.order_id=`main_table`.entity_id', array('skus'  => new Zend_Db_Expr('group_concat(`sales_flat_order_item`.sku SEPARATOR "<br>")')))->group('sales_flat_order_item.entity_id');
        $collection->getSelect()->join('sales_flat_order_payment', 'main_table.entity_id = sales_flat_order_payment.parent_id',array('method'))->group('sales_flat_order_payment.parent_id');
        $this->setCollection($collection);
        return parent::_prepareCollection();
    }

当我评论 COL 1 或 COL 2 下面的行时,这工作正常,但我希望它们同时工作,是如何完成的?(如果我同时使用它们,我会收到错误消息Integrity constraint violation: 1052 Column 'entity_id' in group statement is ambiguous:)

更新答案:

protected function _prepareCollection()
{
    $collection = Mage::getResourceModel($this->_getCollectionClass());
    $collection->getSelect()->join('sales_flat_order_item', '`sales_flat_order_item`.order_id=`main_table`.entity_id', array('skus'  => new Zend_Db_Expr('group_concat(`sales_flat_order_item`.sku SEPARATOR "<br>")')));
    $collection->getSelect()->join('sales_flat_order_payment', 'main_table.entity_id = sales_flat_order_payment.parent_id',array('method'))->group('main_table.entity_id');
    $this->setCollection($collection);
    return parent::_prepareCollection();
}
4

2 回答 2

2

答案在错误中,无法确定应用组的表。您需要明确定义表:

...->group('sales_flat_order_item.entity_id');
于 2013-04-08T11:32:31.247 回答
0

使用 echo (string) $collection->getSelect() 回显您的查询;你会在这里得到一个普通的 sql 查询。在数据库中触发该查询并检查您是否以您想要的方式获得结果。最后但并非最不重要的 Group 也会产生问题。在 magento 中使用 group() 中断 getSelectCountSql看看下面的链接

于 2013-04-08T11:07:32.203 回答