就是要计算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
一句不管怎样,你的程序肯定是有优化的余地的。
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
一句不管怎样,你的程序肯定是有优化的余地的。
解决方案 »
- 怎样通过外键查询到主键的表名?
- mysql \G 问题
- MySQL导入问题,急!!!
- 该怎么把变量写在sql里面啊?
- 使用SELECT * INTO OUTFILE ...出现的"can't create write errcode:22错误"
- C 连接 PostgreSQL 问题.....紧急..
- php连接mysql出现了问题,帮忙解决一下.谢谢
- D6中如何用DBEXPRESS连接到LINUX上的MYSQL?
- 这个编码,真的不能改啊?
- mysql 优化问题 非常非常慢 但是参数看起来没有问题
- vb.net如何与MySql连接
- Mysql 支持视图吗?怎么在手册里查出来是有视图的,但真正创建时又有问题
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)。
select count(1) from student where mphone>='13500000000' and mphone<='13999999999'
group by mphone
我试过把所有学校id放到一个字符串里,然后用
"select count(id) from student where mphone>='13500000000' and mphone<='13999999999' and sid=in("+IdList+") group by groupid,mphone";来查询
但效果也不好,甚至更差
直接select count(id) from student where mphone>='13500000000' and mphone<='13999999999' and group by mphone
不就可以了?
sid=in("+IdList+"
这个条件??
and exists(select * From school where scroll.sid<>1 and scroll.sid=student.sid)
group by mphone
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=
你参照语句的意思自己改一下不就好了?
看看
select count(id) from student where mphone>='13500000000' and mphone<='13999999999'
and sid in (select sid from school where school.sid<>1)
行不行?
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)
都不行
是否就算我在mphone列建立索引mysql都无法使用该索引?