Group by count with two columns

177 Views Asked by At

I would like to group on two different columns and get the count as a nested hash.

User.group('role').count => gives me {"admin" => 10, "user" => 15}

How do i write a query to get result like this(grouping by role and gender)

{"admin" => {"male" => 2, "female" => 3}, "user" => {"male" => 4, "female" => 4}}
0

There are 0 best solutions below