[英]How to Convert this sql query into laravel query builder
select t.product_id,t.on_hand,t.created_at from table
t, (SELECT MAX(purchase_id) as pId FROM table
Group by product_id) tg where t.purchase_id = tg.pId
$result = DB::table('table as t')
->select('t.product_id', 't.on_hand', 't.created_at')
->join(DB::raw('(SELECT MAX(purchase_id) as pId FROM table Group by product_id) tg'), function($join) {
$join->on('t.purchase_id', '=', 'tg.pId');
})->get();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.