Pls help me to write the below code in Ruby on Rails 2.3,
select count(*) as students, batch_id from students group by batch_id;
I want the output of counted students in a variable.
thanks.
Pls help me to write the below code in Ruby on Rails 2.3,
select count(*) as students, batch_id from students group by batch_id;
I want the output of counted students in a variable.
thanks.
Naveed A. wrote in post #1184925:
Pls help me to write the below code in Ruby on Rails 2.3,
select count(*) as students, batch_id from students group by batch_id;
I want the output of counted students in a variable.
thanks.
I tried this:
@total_count = Student.all(:joins => [“INNER JOIN students on
students.batch_id = batches.id”],
:conditions=>{:‘batches.is_deleted’ => false,:‘batches.is_active’
=> true}).count
but it give me the following error:
Mysql::Error: Not unique table/alias: ‘students’: SELECT students
.*
FROM students
INNER JOIN students on students.batch_id = batches.id
WHERE (batches
.is_active
= 1 AND batches
.is_deleted
= 0)
Pls help.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs