繁体   English   中英

操作计数不同的 id

[英]Operation count different id's

我需要做这个操作:

introducir la descripción de la imagen aquí

计算每条记录的总和,具有不同的 'rrpp':1,2,3,4 ∞

我总是用它来总结 RRPP 的记录:

  $variable = Modelo::where('dia_id' , $request->id)->where('rrpp' , 1)->count('id');

但是这样我只能得到1的结果。 而我需要的是得到这样的结果

帮助,谢谢

你只得到结果 1 因为你在查询中使用了这个where('dia_id', $request->id) ,如果你想计算 rrpp=1 使用这个查询:

$variable = Modelo::where('rrpp' , 1)->count('id');

如果你想计算所有 rrpp 使用这个查询:

$variable = Modelo::select('rrpp', 
    DB::raw('count(*) as total'))
    ->groupBy('rrpp')
    ->get()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM