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);
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”)’)
On Sep 23, 2008, at 8:35 AM, Maurício Linhares wrote:
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.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]