Magento按相对值筛选

Magento按相对值筛选,magento,Magento,我想按每行的相对值筛选集合。比如说, SELECT * FROM table WHERE column_1 > column_2 在Magento我知道的唯一一件事就是 $q = Mage::getModel('table')->getCollection() ->addAttributeToFilter('column_1', array('gt' => $some_number)); 或者类似的东西。我只能给它一个值进行比较,而不是一个列名。我还

我想按每行的相对值筛选集合。比如说,

SELECT * FROM table WHERE column_1 > column_2
在Magento我知道的唯一一件事就是

$q = Mage::getModel('table')->getCollection()
         ->addAttributeToFilter('column_1', array('gt' => $some_number));
或者类似的东西。我只能给它一个值进行比较,而不是一个列名。我还查看了
where
子句中的
Zend\u Db\u Select
方法,但没有找到任何有用的方法。我真的必须一直使用直接SQL查询吗(当然,这是不惜一切代价避免的)?(我正在运行Magento 1.3.2.4)


谢谢。

好的,这可能不是理想的解决方案,但这是获得所需的一种方法

这就是我如何得到一系列正在销售的产品,其中产品的最终价格低于其价格

我首先做了一个新的空数据收集。然后定义了我要循环过滤的集合。在那之后,我循环了这个集合,所有符合我需求的产品都被添加到空集合中

    $this->_itemCollection = new Varien_Data_Collection();

    $collection = Mage::getResourceModel('catalog/product_collection');
    $collection->setVisibility(Mage::getSingleton('catalog/product_visibility')->getVisibleInCatalogIds());

    $category = Mage::getModel('catalog/category')->load($this->getCategoryId());

    $collection = $this->_addProductAttributesAndPrices($collection)
        ->addStoreFilter()
        ->addCategoryFilter($category)
        ->addAttributeToSort('position', 'asc');

    $i=0;
    foreach($collection as $product){
        if($product->getFinalPrice() > $product->getPrice() && !$this->_itemCollection->getItemById($product->getId())){    
            $this->_itemCollection->addItem($product);
            $i++;
        }

        if($i==$this->getProductsCount()){
            break;
        }
    }

    $this->setProductCollection($this->_itemCollection);
试试像这样的东西

$q = Mage::getModel('table')->getCollection()
    ->addAttributeToSelect('column_1')
    ->addAttributeToSelect('column_2')
    ->addAttributeToFilter('column_1', array('gt' => Zend_Db_Expr('`column_2`')));

谢谢,但是我正在寻找一种方法来执行查询中的
if($product->getFinalPrice()>$product->getPrice()
,但出于性能原因,这不是用PHP实现的。你明白了吗?我希望有一个解决方案!请更具体一点。我想说,这在很大程度上取决于你所谈论的特定类型的集合(例如,“目录/产品”、“销售/订单”、自制)。集合可以是非常不同的类型(使用平面和/或EAV、使用联接或不使用联接等)。什么集合导致了当前的问题?您尝试比较默认Mage字段或自定义添加的列?还是自定义表?