简体   繁体   中英

Operation count different id's

i need to do this operation:

introducir la descripción de la imagen aquí

Count the total of each number of records with a different 'rrpp': 1,2,3,4 ∞

I always use this to sum the records of a 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. 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:

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

if you want to count all rrpp use this query:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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