//按时间段查询
public ResultSet getByShiJianDuan(String dateFirst,String dateLast){
conn=new GetConn().getConn();
String sql="select xiaoshoudan.*, xiaoshoudan_shangping.* from xiaoshoudan,xiaoshoudan_shangping where " +
"XiaoShouDan_xiaoshoudanhao=xiaoshoudanhao and date between SELECT DATE_SUB('"+dateFirst+"', INTERVAL 1 DAY) and SELECT DATE_SUB('"+dateLast+"', INTERVAL 1 DAY) ";
try {
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
public ResultSet getByShiJianDuan(String dateFirst,String dateLast){
conn=new GetConn().getConn();
String sql="select xiaoshoudan.*, xiaoshoudan_shangping.* from xiaoshoudan,xiaoshoudan_shangping where " +
"XiaoShouDan_xiaoshoudanhao=xiaoshoudanhao and date between SELECT DATE_SUB('"+dateFirst+"', INTERVAL 1 DAY) and SELECT DATE_SUB('"+dateLast+"', INTERVAL 1 DAY) ";
try {
stmt=conn.createStatement();
rs=stmt.executeQuery(sql);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return rs;
}
解决方案 »
- About the INNER JOIN its order
- 【求助】两个表tb_account & tb_user 都是 Innodb类型的,在一个事物中进行数据插入操作,tb_account数据插入成功了,tb_use
- MYSQL出错——Out Of Memory
- 求救SQL语句,高手进来
- mysql的union all问题
- ***请问如何获得表中的最小可用id?马上给分!***
- MYSQL的请求服务数量
- 请问如何写一个写shell文件,从mysql数据库中读取数据?
- MySQL 递归查询
- 如何动态查询缴费记录?高手指点指点
- mysql复习时乱码再现!
- 关于in和exists的优化问题,搜索无准确结果,在MYSQL
建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
1. 你的 create table xxx .. 语句
2. 你的 insert into xxx ... 语句
3. 结果是什么样,(并给以简单的算法描述)
4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。