I''m having an issue generating a cumulative sum by month in rails. This is what I have: @results = Student.connection.select_all("SELECT x1.MonthNo , x1.MonthName , x1.Added , SUM(x2.Added) AS RunningTotal FROM ( SELECT MONTH(passed_on) AS MonthNo , MONTHNAME(passed_on) AS MonthName , COUNT(*) AS Added FROM students WHERE passed_on >= ''2009-09-23'' GROUP BY MONTH(passed_on) ) AS x1 INNER JOIN ( SELECT MONTH(passed_on) AS MonthNo , MONTHNAME(passed_on) AS MonthName , COUNT(*) AS Added FROM students WHERE passed_on >= ''2009-09-23'' GROUP BY MONTH(passed_on) ) AS x2 ON x1.MonthNo >= x2.MonthNo GROUP BY x1.MonthNo;") @result = @results.map{ |result| result[:RunningTotal] } @result returns this: [nil, nil] even though @results returns this: [{"RunningTotal"=>"1", "MonthName"=>"February", "Added"=>"1", "MonthNo"=>"2"}, {"RunningTotal"=>"11", "MonthName"=>"March", "Added"=>"10", "MonthNo"=>"3"}] I would like @result to return this: [1,11] Any suggestions thanks? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On Apr 7, 3:48 pm, John Merlino <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> > @result returns this: > > [nil, nil] > > even though @results returns this: > > [{"RunningTotal"=>"1", "MonthName"=>"February", "Added"=>"1", > "MonthNo"=>"2"}, {"RunningTotal"=>"11", "MonthName"=>"March", > "Added"=>"10", "MonthNo"=>"3"}] > > I would like @result to return this: > [1,11] >> Any suggestions thanks?Symbols and strings are not the same thing Fred --> Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Frederick Cheung wrote:> On Apr 7, 3:48�pm, John Merlino <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote: >> >> I would like @result to return this: >> [1,11] >> > >> Any suggestions thanks? > > Symbols and strings are not the same thing > > Fred > > --But even this: @result = @results.map{ |result| result[''RunningTotal''] } returns this: ["1", "11"] Which is not helping me either, because I believe I need something like this: [1,11] for the chart I''m using. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Nevermind I figured it out. I just need to_i -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.