选择多个列时,按一列分组[laravel]

时间:2017-03-14 04:06:06

标签: php jquery sql database laravel-5

我有这个查询工作正常,但我想选择一个列而不将它放在GroupBy中我该怎么办

我的查询

$navigation_data_unassigned = DB::table('ccctadm.Shipment')->select('ccctadm.documentruleset.status','rulesetname', 'icon', DB::raw('COUNT(*) As Total'))->join('ccctadm.documentruleset', function ($join) {
   $join->on('ccctadm.Shipment.customergroupcode', '=', 'ccctadm.documentruleset.customergroupcode')->on('ccctadm.Shipment.shipmentcategory', '=', 'ccctadm.documentruleset.shipmentcategory')->on('ccctadm.Shipment.status', '=', 'ccctadm.documentruleset.status');
})->whereNotIn('ccctadm.Shipment.id', function ($query) {
        $query->select('shipmentid')->from('ccctadm.shipassign');
})->Where('shipment_cycle', '!=', 'closed')->groupBy('rulesetname', 'icon')->get();

以下查询将返回

 rulesetname    icon          total 
 ---------------------------------------
 release        fdsdsf.png      20     
 blank          fdsdsf.png      20     
 restricted     fdsdsf.png      20     

我想添加更多列

    rulesetname      icon       status         total   
     ---------------------------------------------------
     release        fdsdsf.png   shipped         20     
     blank          fdsdsf.png   pending         20     
     restricted     fdsdsf.png   shipped         20  

所以我想选择状态列并返回其数据而不在groupby中添加

1 个答案:

答案 0 :(得分:0)

只需删除/跳过您的GroupBy查询

Where('shipment_cycle', '!=', 'closed')->groupBy('rulesetname', 'icon')->get();

成为这个

Where('shipment_cycle', '!=', 'closed')->get();