I have a table birds.
I want to count each kind of birds in a single query.
I want to combine these queries into a single query in Eloquent if possible.
select count(id) as count1 from birds where kind = a;
select count(id) as count2 from birds where kind = b;
select count(id) as count2 from birds where kind = c;
I tried something like
$first = DB::table('birds')->selectRaw('count(id) as count1')->where('kind','a');
DB::table('birds')->selectRaw('count(id) as count2')->where('kind','b')->unionAll($first)->get();
i don't think union is giving me what i want.
i just need something like
DB::raw(' (select count(id) from birds where kind = a) as count1 ', ' (select count(id) from birds where kind = a) as count2 ', ' (select count(id) from birds where kind = a) as count3 ')
i want to combine the queries
like
Select ( select count(id) from birds where kind = 'a') as count1, ( select count(id) from birds where kind = 'b') as count2, ( select count(id) from birds where kind ='c') as count3 from birds ;
. please give me a tip how to achieve it.