[英]Operation count different id's
i need to do this operation:我需要做这个操作:
Count the total of each number of records with a different 'rrpp': 1,2,3,4 ∞计算每条记录的总和,具有不同的 'rrpp':1,2,3,4 ∞
I always use this to sum the records of a RRPP:我总是用它来总结 RRPP 的记录:
$variable = Modelo::where('dia_id' , $request->id)->where('rrpp' , 1)->count('id');
but this way I only get the result of 1 in specific.但是这样我只能得到1的结果。 And what I need is to get the result like this
而我需要的是得到这样的结果
help, thanks帮助,谢谢
you only get result 1 because you use this where('dia_id', $request->id)
in your query, if you want to count rrpp=1 use this query:你只得到结果 1 因为你在查询中使用了这个
where('dia_id', $request->id)
,如果你想计算 rrpp=1 使用这个查询:
$variable = Modelo::where('rrpp' , 1)->count('id');
if you want to count all rrpp use this query:如果你想计算所有 rrpp 使用这个查询:
$variable = Modelo::select('rrpp',
DB::raw('count(*) as total'))
->groupBy('rrpp')
->get()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.