Lavarel子查询
更新:HHH   时间:2023-1-7


源生sql
select from (select from service_order order by order_time asc) a group by a.company_id;

 $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);
返回web开发教程...