@teachers_count=User.find_by_sql("SELECT COUNT(users.`id`) AS teacher_count FROM users LEFT JOIN user_extensions ON users.id=user_extensions.user_id WHERE
@students_count=User.find_by_sql("SELECT COUNT(users.`id`) AS student_count FROM users LEFT JOIN user_extensions ON users.id=user_extensions.user_id WHERE
# user_ids = User.find_by_sql("SELECT users.id FROM users LEFT JOIN user_extensions ON users.id=user_extensions.user_id WHERE user_extensions.`school_id` = #{@school.id}").map(&:id)
@shixuns_count=Shixun.find_by_sql("select count(s.id) as shixun_count from users u right join shixuns s on u.id=s.user_id and s.status in (2, 3) inner join user_extensions ue on
@shixun_time_sum=(Game.find_by_sql("select sum(g.cost_time) cost_time from users u RIGHT join games g on u.id=g.user_id inner join user_extensions ue on
# select count(sw.id) from users u left join student_works sw on u.id=sw.user_id and sw.myshixun_id is not null and sw.work_status !=0 inner join user_extensions ue on u.id=ue.user_id and ue.school_id=117 ;
# @shixun_report_count = StudentWork.where("work_status != 0 and user_id in (#{user_ids.join(',').strip == "" ? -1 : user_ids.join(',')}) and myshixun_id is not null").count
@shixun_report_count=StudentWork.find_by_sql("SELECT count(*) as sw_count FROM `student_works` where user_id in (SELECT users.id FROM users RIGHT JOIN user_extensions ON users.id=user_extensions.user_id WHERE
@teachers=User.find_by_sql("SELECT users.id, users.login, users.lastname, users.firstname, users.nickname, IFNULL((SELECT count(shixuns.id) FROM shixuns where shixuns.user_id =users.id group by shixuns.user_id), 0) AS publish_shixun_count,
(SELECTcount(c.id)FROMcoursesc,course_membersmWHEREc.id!=1309andm.course_id=c.idANDm.rolein(1,2,3)andc.school_id=#{@school.id} AND m.user_id=users.id AND c.is_delete = 0) as course_count
FROM`users`,user_extensionsuewhereusers.id=ue.user_idandue.identity=0andue.school_id=#{@school.id} ORDER BY publish_shixun_count desc, course_count desc, id desc LIMIT 10")
course_ids=Course.find_by_sql("SELECT c.id FROM courses c, course_members m WHERE c.id != 1309 and m.course_id = c.id AND m.role in (1,2,3) AND m.user_id=#{teacher.id} AND c.is_delete = 0 and c.school_id = #{@school.id}")
myshixun_ids=StudentWork.select("myshixun_id").where("homework_common_id in (#{homeworks.map(&:id).join(',').strip==""?-1:homeworks.map(&:id).join(',')}) and myshixun_id is not null")
user_ids=User.find_by_sql("SELECT users.id FROM users, user_extensions WHERE users.id=user_extensions.user_id AND user_extensions.`school_id` = #{@school.id}").map(&:id)
users.id=ue.user_idwhereue.school_id=#{@school.id} AND ue.identity = 1 AND `users`.`type` IN ('User', 'AnonymousUser') ORDER BY experience DESC, myshixun_count DESC LIMIT 10")
same_count=Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ONoutputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(end_day-365.days).beginning_of_day}' AND outputs.created_at < '#{(end_day-365.days).end_of_day}'").first.try(:count).to_i
last_count=Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ONoutputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(end_day-1.day).beginning_of_day}' AND outputs.created_at < '#{(end_day-1.day).end_of_day}'").first.try(:count).to_i
@eval_data<<Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ONoutputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{end_day.beginning_of_day+(i*2).hour}' AND outputs.created_at < '#{end_day.beginning_of_day+((i+1)*2).hour}'").first.try(:count).to_i
same_count=Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ONoutputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day-365.days).beginning_of_day}' AND outputs.created_at < '#{(end_day-365.days).end_of_day}'").first.try(:count).to_i
last_count=Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ONoutputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day-7.days).beginning_of_day}' AND outputs.created_at < '#{(end_day-7.days).end_of_day}'").first.try(:count).to_i
@eval_data<<Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ONoutputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day+i.days).beginning_of_day}' AND outputs.created_at < '#{(start_day+(i+1).days).end_of_day}'").first.try(:count).to_i
same_count=Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ONoutputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day-365.days).beginning_of_day}' AND outputs.created_at < '#{(end_day-365.days).end_of_day}'").first.try(:count).to_i
last_count=Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ONoutputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day-30.days).beginning_of_day}' AND outputs.created_at < '#{(end_day-30.days).end_of_day}'").first.try(:count).to_i
@eval_data<<Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ONoutputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day+(3*i).days).beginning_of_day}' AND outputs.created_at < '#{(start_day+(3*(i+1)).days).end_of_day}'").first.try(:count).to_i
same_count=Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ONoutputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day-365.days).beginning_of_day}' AND outputs.created_at < '#{(end_day-365.days).end_of_day}'").first.try(:count).to_i
@eval_data<<Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
ONoutputs.`game_id` = b.id WHERE outputs.test_set_position = 1 AND outputs.created_at > '#{(start_day+i.days).beginning_of_day}' AND outputs.created_at < '#{(start_day+(i+1).days).end_of_day}'").first.try(:count).to_i
@total_count=Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b
@trend_count=Output.find_by_sql("select count(outputs.id) as count from outputs RIGHT JOIN (SELECT games.id FROM games RIGHT JOIN user_extensions ue ON games.`user_id` = ue.`user_id` AND ue.`school_id`=#{@school.id}) b