Hello, currently I am running something similar to this command:
Person.sum(:cholesterol, :group => :age)
which seems to work great when I have a small number of records. However when I attempt to call this with a few thousand records or more in the table, it takes literally minutes to run. However, the SQL querey:
SELECT sum(`people`.cholesterol) AS sum_cholesterol, age AS age FROM `people` GROUP BY age
takes around 0.02 seconds on the same thousand number of records. Once I have the data I dont need to do much more than display it. Is there a more efficient way of doing this? I am aware that I can manually make sql queries from models and controllers, I dont know if this would be a viable option as I have not found a clear way to work with the result once the query is made.