尝试在Magento加入中分组时出错
我面临着与Magento的标题错误。我试图按县对网格中的记录进行分组,县是在联接中获得的字段之一,而不是主表。当我运行针对DB生成的SQL查询时,它会按预期运行,但当尝试访问Magento中的网格时,我会收到该错误。这是我的加入:尝试在Magento加入中分组时出错,magento,join,grid,grouping,Magento,Join,Grid,Grouping,我面临着与Magento的标题错误。我试图按县对网格中的记录进行分组,县是在联接中获得的字段之一,而不是主表。当我运行针对DB生成的SQL查询时,它会按预期运行,但当尝试访问Magento中的网格时,我会收到该错误。这是我的加入: $collection = Mage::getModel('sales/order_address')->getCollection(); $collection ->addAttributeToSelect('re
$collection = Mage::getModel('sales/order_address')->getCollection();
$collection
->addAttributeToSelect('region')
->addAttributeToSelect('city')
->addAttributeToFilter('address_type', 'shipping')
->addAttributeToFilter('region', 'California')
->addAttributeToFilter('created_at', array('from' => $from, 'to' => $to))
->addFieldToFilter(array('status', 'status'),
array(
array('eq' => 'complete'),
array('eq' => 'processing')
));
$collection->getSelect()->joinLeft(
array('order' => 'sales_flat_order'),
'order.entity_id = main_table.parent_id',
array('status' => 'order.status',
'created_at' => 'order.created_at',
'grand_total' => 'SUM(order.grand_total)'))
->joinLeft(
array('order_tax' => 'sales_order_tax'),
'order_tax.order_id = main_table.parent_id',
array('county' => 'order_tax.title',
'tax_amount' => 'SUM(order_tax.amount)',
'tax_rate' => 'order_tax.percent'))
->group('county')
->group('city')
->distinct(true);
这是生成的SQL:
SELECT DISTINCT `main_table`.`region`, `main_table`.`city`, `order`.`status`, `order`.`created_at`, SUM(order.grand_total) AS `grand_total`, `order_tax`.`title` AS `county`, SUM(order_tax.amount) AS `tax_amount`, `order_tax`.`percent` AS `tax_rate` FROM `sales_flat_order_address` AS `main_table` LEFT JOIN `mvmt_sales_flat_order` AS `order` ON order.entity_id = main_table.parent_id LEFT JOIN `mvmt_sales_order_tax` AS `order_tax` ON order_tax.order_id = main_table.parent_id WHERE (address_type = 'shipping') AND (region = 'California') AND (created_at >= '2013-08-01 00:00:00' AND created_at <= '2013-12-31 00:00:00') AND ((status = 'complete') OR (status = 'processing')) GROUP BY `county`, `city`
有人知道这里发生了什么,为什么SQL接受查询而不是Magento吗
提前谢谢你的帮助
$collection = Mage::getModel('sales/order_address')->getCollection();
$collection
->addAttributeToSelect('region')
->addAttributeToSelect('country_id')
->addAttributeToSelect('city')
->addAttributeToFilter('address_type', 'shipping')
->addAttributeToFilter('region', 'California')
->addAttributeToFilter('created_at', array('from' => $from, 'to' => $to))
->addFieldToFilter(array('status', 'status'),
array(
array('eq' => 'Pending'),
array('eq' => 'processing')
));
$collection->getSelect()->joinLeft(
array('order' => 'sales_flat_order'),
'order.entity_id = main_table.parent_id',
array('order.status','order.created_at','SUM(order.grand_total)'));
$collection->getSelect()
->joinLeft(
array('order_tax' => 'sales_order_tax'),
'order_tax.order_id = main_table.parent_id',
array('order_tax.title','SUM(order_tax.amount)','order_tax.percent'))
->group('country_id')
->group('city')
->distinct(true);
希望这对你有用
祝你好运。将你的联系信息传播到各地可能会被认为是。。。垃圾邮件-请将其从您的所有回复中删除我感谢您的时间,但这不是关于CONTRY,而是关于COUNTY,这是我分配给字段的别名:order_tax.title。