Jarfis
Jarfis

Reputation: 125

Rails - Sum a column after having already grouped the results

I have a bunch of records that are grouped and I need to sum the columns of all them

When I just to the regular results.sum(:col_name) it gives me something along the lines of {1 => 2, 2 => 1, 3 => 15}, but I need (in this example) 18

Upvotes: 0

Views: 17

Answers (1)

Deepak Mahakale
Deepak Mahakale

Reputation: 23671

Just sum the values then

results.sum(:col_name).values.sum

Upvotes: 1

Related Questions