Php Laravel中的不同值

Php Laravel中的不同值,php,laravel,laravel-5,laravel-5.2,laravel-5.1,Php,Laravel,Laravel 5,Laravel 5.2,Laravel 5.1,你好,朋友,我正在使用以下查询: $cur_date = date('Y-m-d'); $clientTemp = DB::table('clients')->where('quotations.exp_date','<',$cur_date) ->join('quotations','quotations.customer_id','=','clients.id') ->get() ->map(function ($cli

你好,朋友,我正在使用以下查询:

$cur_date = date('Y-m-d');
   $clientTemp = DB::table('clients')->where('quotations.exp_date','<',$cur_date)
     ->join('quotations','quotations.customer_id','=','clients.id')
      ->get()
       ->map(function ($clientTemp) {
        return [
            'id' => $clientTemp->id,
            'hash' => $clientTemp->hash,
            'name' => $clientTemp->first_name.' '.$clientTemp->last_name,
            'email' => $clientTemp->email,
            'mobile' => $clientTemp->mobile
        ];
    });
我从两个表中获取此数据:

一,。提问和2。客户

在报价表中,如果exp_日期小于当前日期,则将从客户表中获取详细信息

但有可能报价表中有超过1行,但我只想从客户id唯一的表中提取一行。如何从报价表中获取具有相同客户id的唯一行

您应该使用groupby

$cur_date = date('Y-m-d');    $clientTemp = DB::table('clients')->where('quotations.exp_date','<',$cur_date)
     ->join('quotations','quotations.customer_id','=','clients.id')
     ->->groupBy('quotations.customer_id')
      ->get()
       ->map(function ($clientTemp) {
        return [
            'id' => $clientTemp->id,
            'hash' => $clientTemp->hash,
            'name' => $clientTemp->first_name.' '.$clientTemp->last_name,
            'email' => $clientTemp->email,
            'mobile' => $clientTemp->mobile
        ];
    });
你应该使用groupby

$cur_date = date('Y-m-d');    $clientTemp = DB::table('clients')->where('quotations.exp_date','<',$cur_date)
     ->join('quotations','quotations.customer_id','=','clients.id')
     ->->groupBy('quotations.customer_id')
      ->get()
       ->map(function ($clientTemp) {
        return [
            'id' => $clientTemp->id,
            'hash' => $clientTemp->hash,
            'name' => $clientTemp->first_name.' '.$clientTemp->last_name,
            'email' => $clientTemp->email,
            'mobile' => $clientTemp->mobile
        ];
    });

您需要使用GROUPBY子句,但由于MySQL默认的ONLY_FULL_GROUP_BY模式,您必须聚合任何具有多个值的列

您似乎没有实际使用引号中的任何值,因此您可以添加:

DB::table('clients')->select('clients.*')->groupBy('clients.id')...
否则,您需要告诉MySQL如何聚合具有多个值的任何行,如:

DB::table('clients')->selectRaw('clients.*, MIN(quotations.id)')->groupBy('clients.id')...

您需要使用GROUPBY子句,但由于MySQL默认的ONLY_FULL_GROUP_BY模式,您必须聚合任何具有多个值的列

您似乎没有实际使用引号中的任何值,因此您可以添加:

DB::table('clients')->select('clients.*')->groupBy('clients.id')...
否则,您需要告诉MySQL如何聚合具有多个值的任何行,如:

DB::table('clients')->selectRaw('clients.*, MIN(quotations.id)')->groupBy('clients.id')...

它正在抛出错误:SQLSTATE[42000]:语法错误或访问冲突:SELECT list的1055表达式36不在GROUP BY子句中,并且包含未聚合的列“billing.quotes.id”,该列在功能上不依赖GROUP BY子句中的列;这与sql不兼容。\u mode=only\u full\u group\u by sql:select*from clients internal join quotes on quotes.customer\u id=clients.id其中quotes.exp\u date<2018-08-25 group by customer\u id抛出错误:SQLSTATE[42000]:语法错误或访问冲突:SELECT列表的1055表达式36不在GROUP BY子句中,并且包含功能上不依赖GROUP BY子句中的列的非聚合列“billing.quotes.id”;这与sql不兼容。\u mode=only\u full\u group\u by sql:select*from clients internal join quotes on quotes.customer\u id=clients.id where quotes.exp\u date<2018-08-25 group by customer\u id您是否使用报价表中的任何列?是否使用报价表中的任何列?返回$datatables->collection$clientTemp->addColumn'actions','@ifSentinel::inRole'admin\'@endif'->removeColumn'id'->rawColumns['actions']->make;}在addColumn中,如何添加客户端id而不是$idreturn$datatables->collection$clientTemp->addColumn'actions','@ifSentinel::inRole'admin\'@endif'->removeColumn'id'->rawColumns['actions']->make;}在addColumn中,如何添加客户端id而不是$id