thinkphp6 leftjoin联表查询时,子表有多条记录去重后获取子表的最新记录查询方法,具体实现的代码如下:
//构建子查询 $ct_sql= Db::name('CustomerTrace')->order('id desc')->buildSql(); $rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit']; $content = CustomerList::where($where) ->field('a.*,ct.follow_time,ct.next_time') ->alias('a') ->join($ct_sql.' ct', 'ct.cid = a.id','LEFT') ->order($orderby) ->group('ct.follow_time') //去重 ->paginate($rows, false, ['query' => $param]);