json.schools @schools.each do |school| pass_count = Myshixun.find_by_sql("select count(ms.id) ms_count from myshixuns ms, user_extensions ue where ue.school_id = #{school.id} and ms.user_id = ue.user_id and ms.status = 1 and shixun_id in (select shixun_id from stage_shixuns where subject_id = '#{@subject.id}')").first.try(:ms_count).to_i json.name school.school_name json.student_count school.ue_count json.pass_count pass_count json.unpass_count school.ue_count - pass_count end