I have a table with workouts with the following key columns:
workout_id distance
1 2.3
2 3.1
Let’s say I want to write a Rails active record query so that I get these columns plus a running total of the distance, like so:
workout_id distance running_total
1 2.3 2.3
2 3.1 5.4
How could I do such a thing?
I agree with HungryCoder that you should perhaps do it in the model rather than in a database query.
Then in the controller, simply do: