Hi everyone. I''m trying to SUM the places of the first 5 finishers in a Cross Country running event. In a Cross Country race the team score is based upon the sum of the top 5 runners on your team. The lowest team score at the competition wins. I have EVENTS(the race), PARTICIPANTS(the runner), and EVENT_PARTICIPANTS(a runner in a race). Within event_participant I have this code, which doesn''t work as it adds places beyond the 5th runner. def self.score_5 self.calculate(:sum, :finish_place, :order => :finish_place, :limit => 5) end It appears that the LIMIT is ignored or is applied after the summation. Any suggestions? --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On 7 Dec 2008, at 19:37, yajiri wrote:> > Hi everyone. > > I''m trying to SUM the places of the first 5 finishers in a Cross > Country running event. In a Cross Country race the team score is > based upon the sum of the top 5 runners on your team. The lowest team > score at the competition wins. > > I have EVENTS(the race), PARTICIPANTS(the runner), and > EVENT_PARTICIPANTS(a runner in a race). > > Within event_participant I have this code, which doesn''t work as it > adds places beyond the 5th runner. > > def self.score_5 > self.calculate(:sum, :finish_place, :order > => :finish_place, :limit => 5) > end > > It appears that the LIMIT is ignored or is applied after the > summation. >It''s applied after (so if you did select sum(foo) from bars limit 5 then you''d only get 5 rows back). Something like SELECT sum(finish_place) from (SELECT * from some_table order by finish_place limit 5) as sub_select should do it. Fred> Any suggestions? > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Are us suggesting find_by_sql? On Dec 7, 1:48 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On 7 Dec 2008, at 19:37, yajiri wrote: > > > > > > > Hi everyone. > > > I''m trying to SUM the places of the first 5 finishers in a Cross > > Country running event. In a Cross Country race the team score is > > based upon the sum of the top 5 runners on your team. The lowest team > > score at the competition wins. > > > I have EVENTS(the race), PARTICIPANTS(the runner), and > > EVENT_PARTICIPANTS(a runner in a race). > > > Within event_participant I have this code, which doesn''t work as it > > adds places beyond the 5th runner. > > > def self.score_5 > > self.calculate(:sum, :finish_place, :order > > => :finish_place, :limit => 5) > > end > > > It appears that the LIMIT is ignored or is applied after the > > summation. > > It''s applied after (so if you did select sum(foo) from bars limit 5 > then you''d only get 5 rows back). > Something like > SELECT sum(finish_place) from > (SELECT * from some_table order by finish_place limit 5) as sub_select > > should do it. > > Fred > > > Any suggestions?--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
I''d like to know if there is a way to use ActiveRecord to do this. Thx On Dec 7, 2:01 pm, yajiri <twno...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Are us suggesting find_by_sql? > > On Dec 7, 1:48 pm, Frederick Cheung <frederick.che...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> > wrote: > > > On 7 Dec 2008, at 19:37, yajiri wrote: > > > > Hi everyone. > > > > I''m trying to SUM the places of the first 5 finishers in a Cross > > > Country running event. In a Cross Country race the team score is > > > based upon the sum of the top 5 runners on your team. The lowest team > > > score at the competition wins. > > > > I have EVENTS(the race), PARTICIPANTS(the runner), and > > > EVENT_PARTICIPANTS(a runner in a race). > > > > Within event_participant I have this code, which doesn''t work as it > > > adds places beyond the 5th runner. > > > > def self.score_5 > > > self.calculate(:sum, :finish_place, :order > > > => :finish_place, :limit => 5) > > > end > > > > It appears that the LIMIT is ignored or is applied after the > > > summation. > > > It''s applied after (so if you did select sum(foo) from bars limit 5 > > then you''d only get 5 rows back). > > Something like > > SELECT sum(finish_place) from > > (SELECT * from some_table order by finish_place limit 5) as sub_select > > > should do it. > > > Fred > > > > Any suggestions?--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---