我的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
Run Code Online (Sandbox Code Playgroud)
我需要将它翻译成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())
Run Code Online (Sandbox Code Playgroud)
但是这不起作用,因为在连接之后应用了where语句导致查询总数小于sales_flat_order_grid.