i have a query, i need to transfer this using all the find conditions etc, can anyone give me a few pointers? select * from outcomes o1 where o1.outcome_date = (select max(o2.outcome_date) from outcomes o2 where o2.testrun_id o1.testrun_id and o2.testcase_id = o1.testcase_id); Outcome.count ?? -- 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-/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 -~----------~----~----~----~------~----~------~--~---
Outcome.find(:all, :conditions => ''outcomes.outcome_date = (select max(o2.outcome_date) from outcomes o2 where o2.testrun_id outcomes.testrun_id and o2.testcase_id = outcomes.testcase_id)'') On Tue, Sep 23, 2008 at 9:31 AM, Brad Symons <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > i have a query, i need to transfer this using all the find conditions > etc, can anyone give me a few pointers? > > select * from outcomes o1 where o1.outcome_date = (select > max(o2.outcome_date) from outcomes o2 where o2.testrun_id > o1.testrun_id and o2.testcase_id = o1.testcase_id); > > Outcome.count ?? > -- > Posted via http://www.ruby-forum.com/. > > > >-- Maurício Linhares http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/ (en) João Pessoa, PB, +55 83 8867-7208 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks. BUt im still struggling, for example, theres a slight change: select count(*) from outcomes o1 where o1.outcome_date = (select max(o2.outcome_date) from outcomes o2 where o2.testrun_id = o1.testrun_id and o2.testcase_id = o1.testcase_id and o1.testrun_id = ''31'' and o1.result_id = ''1''); I want to substitute the ''31'' with instance variable @testrun so in your example, how do i escape the '''' string to insert the instance variable: GUESS in CAPS: ... .... o2.testcase_id = outcomes.testcase_id AND {OUTCOMES.TESTRUN_ID => @TESTRUN} and outcomes.result_id = "1")'') thanks though, i now understand alot more! -- 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-/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 Sep 23, 2008, at 8:35 AM, Maurício Linhares wrote:> > Outcome.find(:all, :conditions => ''outcomes.outcome_date = (select > max(o2.outcome_date) from outcomes o2 where o2.testrun_id > outcomes.testrun_id and o2.testcase_id = outcomes.testcase_id)'') > > On Tue, Sep 23, 2008 at 9:31 AM, Brad Symons > <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> >> i have a query, i need to transfer this using all the find conditions >> etc, can anyone give me a few pointers? >> >> select * from outcomes o1 where o1.outcome_date = (select >> max(o2.outcome_date) from outcomes o2 where o2.testrun_id >> o1.testrun_id and o2.testcase_id = o1.testcase_id); >> >> Outcome.count ?? >> > Maurício Linhares > http://alinhavado.wordpress.com/ (pt-br) | http:// > blog.codevader.com/ (en) > João Pessoa, PB, +55 83 8867-7208On Sep 23, 2008, at 9:01 AM, Brad Symons wrote:> Thanks. > > BUt im still struggling, for example, theres a slight change: > > select count(*) from outcomes o1 where o1.outcome_date = (select > max(o2.outcome_date) from outcomes o2 where o2.testrun_id > o1.testrun_id and o2.testcase_id = o1.testcase_id and o1.testrun_id > ''31'' and o1.result_id = ''1''); > > I want to substitute the ''31'' with instance variable @testrun > > so in your example, how do i escape the '''' string to insert the > instance > variable: > > GUESS in CAPS: > > ... > .... > o2.testcase_id = outcomes.testcase_id AND {OUTCOMES.TESTRUN_ID => > @TESTRUN} and outcomes.result_id = "1")'') > > thanks though, i now understand alot more! > --Building on Maurício''s response: Outcome.find(:all, :conditions => [''outcomes.outcome_date = (SELECT MAX(o2.outcome_date) FROM outcomes AS o2 WHERE o2.testrun_id outcomes.testrun_id AND o2.testcase_id = outcomes.testcase_id) AND outcomes.testrun_id = ? AND outcomes.result_id = ?'', @testrun, ''1'']) You were close. Look at the docs for the conditions value, the form of an array is: ["sql fragment with placeholders'', placeholder_1_value, placeholder_2_value] -Rob Rob Biedenharn http://agileconsultingllc.com Rob-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---