就是要计算studenttotal吗?
while(SchoolRs.next()){//351次循环
ResultSet stuRs = aDBC.SelectDB(db, false, "", "select count
(id) from student where mphone>='13500000000' and mphone<='13999999999' and sid in("+SIDList+") group by groupid,mphone"); //这一句代码用到了SchoolRs里的东西吗?
还是你的代码不全?我感觉你的代码相当于
select count
(id) from student where mphone>='13500000000' and mphone<='13999999999' and sid <>1 group by sid,groupid,mphone
一句不管怎样,你的程序肯定是有优化的余地的。

解决方案 »

  1.   

    打错了,代码是这样:
     String SchoolSql="select sid from school where sid<>1";
               ResultSet SchoolRs=aDBC.SelectDB(db,false,"",SchoolSql);
               if(SchoolRs!=null){
                 while(SchoolRs.next()){//351次循环
                    ResultSet stuRs = aDBC.SelectDB(db, false, "", "select count(id) from student where mphone>='13500000000' and mphone<='13999999999' and sid=SchoolRs.getString(sid) group by groupid,mphone");
                   if (stuRs != null) {
                         stuRs.last();
                         this.studenttotal += stuRs.getRow();
                         stuRs.close();
                         stuRs = null;
                    }
                 }
                SchoolRs.close();
                SchoolRs=null;
               }  程序是用来统计所有学校的学生数目(同一班级中多个相同的手机号码的学生算一个?,其实也不是,因为groupid是字符串类型,学生属于多个班级时groupid用逗号分隔不同的班级id)。
      

  2.   

    不同学校中不会有同一个学生吧?
    select count(1) from student where mphone>='13500000000' and mphone<='13999999999' 
    group by mphone
      

  3.   

    可能有,不过这方面不考虑了
      我试过把所有学校id放到一个字符串里,然后用
      "select count(id) from student where mphone>='13500000000' and mphone<='13999999999' and sid=in("+IdList+") group by groupid,mphone";来查询
      但效果也不好,甚至更差
      

  4.   

    要这样干什么?
    直接select count(id) from student where mphone>='13500000000' and mphone<='13999999999' and group by mphone
    不就可以了?
      

  5.   

    为什么一定要加
    sid=in("+IdList+"
    这个条件??
      

  6.   

    因为数据库里面可能有不属于任何学校的学生,in ("+IdList+") 或循环sid=SchoolRs.getString(sid) 就是保证统计出来的数目不包括这些学生,至于要加group by groupid,是因为以前旧系统中是这样统计,而且业务也认定了按这个方法统计出来的数据,要求新版系统中统计时也一定要这个数据
      

  7.   

    select count(id) from student where mphone>='13500000000' and mphone<='13999999999' 
    and exists(select * From school where scroll.sid<>1 and scroll.sid=student.sid)
    group by mphone
      

  8.   

    select count(id) from student where mphone>='13500000000' and mphone<='13999999999'
    and  exists(select * from school where school.sid<>1 and school.sid=student.sid)
    group by mphoneYou have an error in your SQL syntax.  Check the manual that corresponds to your MySQL server version for the right syntax to use near 'exists(select * from school where school.sid<>1 and school.sid=
      

  9.   

    我对MYSQL的具体语法不熟悉。
    你参照语句的意思自己改一下不就好了?
    看看
    select count(id) from student where mphone>='13500000000' and mphone<='13999999999'
    and  sid in (select sid from school where school.sid<>1)
    行不行?
      

  10.   

    MYSQL不支持子查询,所以
    select count(id) from student where mphone>='13500000000' and mphone<='13999999999'
    and  exists(select * from school where school.sid<>1 and school.sid=student.sid)
    group by mphone  select count(id) from student where mphone>='13500000000' and mphone<='13999999999'
    and  sid in (select sid from school where school.sid<>1)
    都不行
      
      

  11.   

    mphone>='13500000000' and mphone<='13999999999'
       是否就算我在mphone列建立索引mysql都无法使用该索引?