I have the following line of code which works in sqlite, but in PostGres doesn't:
@income_by_category = SoldCategory.group(:category_name).having("branch_id=?", @branch_id).sum(:total).to_a
It's basically grouping all the SoldCategory
by :category_name
that have the same @branch_id
, adding all their :total
's, and converting it to an array. I'm using it to provide some data to some charts. It gives me a result similar to this:
[['shoes', 5000], ['pants', 6000], ['shirts', 7000]]
How can I achieve the same result using PostGress?