源生sql
select from (select from service_order order by order_time asc) a group by a.company_id;成都創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供望都網(wǎng)站建設(shè)、望都做網(wǎng)站、望都網(wǎng)站設(shè)計(jì)、望都網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁(yè)設(shè)計(jì)與制作、望都企業(yè)網(wǎng)站模板建站服務(wù),十余年望都做網(wǎng)站經(jīng)驗(yàn),不只是建網(wǎng)站,更提供有價(jià)值的思路和整體網(wǎng)絡(luò)服務(wù)。
$subQuery = ServiceOrder::select(['id', 'company_id', 'service_id', 'order_time'])
->where('project', 'yundou')
->orderBy('order_time', 'asc');
$sql = $subQuery->toSql();
$query = DB::table(DB::raw("({$sql}) as sub"))
->groupBy('sub.company_id');
$result = $query->mergeBindings($subQuery->getQuery())->paginate(10);