我正在尝试通过覆盖 Catalog/Product/List.php 来使用当前产品集合检索畅销产品
<?php
if($this->getRequest()->getParam('best')==1){
$this->_productCollection->getSelect()
->joinLeft(array('items'=>'sales_flat_order_item'), "items.product_id = e.entity_id", array('count'=>'SUM(qty_ordered)'))
->group('e.entity_id');
$this->_productCollection->getSelect()->having('SUM(items.qty_ordered) > ?',0);
return $this->_productCollection;
}
?>
使用上面的代码,我得到以下 SQL 错误,该错误是由于 having 子句引起的,我如何在上面的代码中使用 havinh 子句来避免结果行具有 qty_ordered<1
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'items.qty_ordered' in 'having clause'