Postgresql Group By Count In R