cumulative sum by month

J

John Merlino

Hey all,

While it is possible to doc cumulative sum by month in mysql using MONTH
and COUNT statements, I'm trying to figure out if the same kind of
statement is available in ruby, something like a substitute for the
month value I put below:

def cumulative_sum
values = [:passed_on, :failed_on, :incompleted_on]
sum = 0
case values
when :passed_on
month.each do |state|
while state > '2010-03-00'
@passed_on = state.map{ |x| sum += x}
end
end

when :failed_on
month.each do |state|
while state > '2010-03-00'
@failed_on = state.map{ |x| sum += x}
end
end

when :incompleted_on
month.each do |state|
while state > '2010-03-00'
@incompleted_on = state.map{ |x| sum += x}
end
end
end
end

Note that the passed_on, failed_on and incompleted_on fields of students
table are data typed as date.
Thanks for any response.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top