select `check` from zz_subsidy where id=t1.sub_id 在这限制不好吗

解决方案 »

  1.   

    from zz_student t1 where sub_check=2 order by stu_id desc limit 0,30
    最后改成这样试试P.S 是不是应该考虑优化一下数据库结构了,为了读一个字段就要连一个表,这个语句跑起来效率也是个问题
      

  2.   

    不是效率问题,而是方法学习的问题,这个在php中使用不但不会降低效率,反而会因为mysql的非重复查询而加快速度
    已经解决 ,标准方法
    1.
    select * from ( 
    select t1.stu_id, t1.class,name, t1.per_check, t1.pen_id, t1.loan_id, t1.sch_id, t1.sti_id, t1.sub_id, (select `check` from zz_penury where id=t1.pen_id ) as pen_check, (select `check` from zz_loan where id=t1.loan_id ) as loan_check, (select `check` from zz_scholarship where id=t1.sch_id ) as sch_check, (select `check` from zz_stipend where id=t1.sti_id ) as sti_check, (select `check` from zz_subsidy where id=t1.sub_id ) as sub_check, t1.id from zz_student as t1  order by stu_id desc limit 0,30) a 
    where sub_check=2 2.
    select t1.stu_id, t1.class,name, t1.per_check, t1.pen_id, t1.loan_id, t1.sch_id, t1.sti_id, t1.sub_id, (select `check` from zz_penury where id=t1.pen_id ) as pen_check, (select `check` from zz_loan where id=t1.loan_id ) as loan_check, (select `check` from zz_scholarship where id=t1.sch_id ) as sch_check, (select `check` from zz_stipend where id=t1.sti_id ) as sti_check, (select `check` from zz_subsidy where id=t1.sub_id ) as sub_check, t1.id from zz_student as t1 
    where exists (select `check` from zz_subsidy where id=t1.sub_id  and `check`=2 ) 
    order by stu_id desc limit 0,30  .