我的SQL查询语句如下:
SELECT * FROM `sales_flat_order_grid` AS `main_table`
LEFT JOIN (SELECT * from `customer_address_entity_varchar`
WHERE attribute_id=31) AS `ce3`
ON main_table.customer_id=ce3.entity_id
我需要将其翻译成Magento风格。
我试过了
$collection = Mage::getResourceModel('sales/order_grid_collection');
$tel = Mage::getModel('eav/entity_attribute')->loadByCode('2', 'telephone');
$collection->getSelect()
->joinLeft(array('ce3' => 'customer_address_entity_varchar'), 'main_table.customer_id=ce3.entity_id', array('telephone' => 'value'))
->where('ce3.attribute_id='.$tel->getAttributeId())
但这是行不通的,因为联接之后应用了where语句,导致查询总数小于sales_flat_order_grid。
最佳答案
我相信这可以解决您的问题:
$collection -> getSelect() -> joinLeft(array("oauth"=>'customer_entity_varchar'),
'main_table.customer_id=oauth.entity_id and oauth.attribute_id = 156',
array('OauthProvider' => "value"));
关于mysql - magento集合的条件joinLeft,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23988873/