浏览文章
文章信息
Magento2 left join select max id in join table | 左链接取连接表最新的一条数据
14340
代码示例:
# 添加原始成本 $this->collection->getSelect()->columns()->joinLeft( 'aiweline_pricemanager_costchangelog', 'aiweline_pricemanager_costchangelog.sku=e.sku AND aiweline_pricemanager_costchangelog.costchangelog_id in (select max(costchangelog_id) from aiweline_pricemanager_costchangelog group by product_id order by created_at DESC)', ['aiweline_pricemanager_costchangelog.sku as cost_sku','aiweline_pricemanager_costchangelog.origin_cost as origin_cost'] );