sql和java分别判断 一天之内的记录

[img]http://dl.iteye.com/upload/picture/pic/84841/56511df5-1fec-3fd6-b9c1-55af660c0597.jpg[/img]

我想要在上图中五条记录中搜出来从2011/3/23 00:00:00到2011/3/24 00:00:00的记录,也就是搜出来前四条记录。


请问sql语句怎么写啊?

最好把纯java语句写出来也是最好的啦,谢谢各位

数据库名是 :temporary

数据库为 oracle 10G

select * from temporary where trunc(createtime)=trunc(sysdate)



select * from temporary where to_char(createtime,'yyyy-mm-dd')=to_char(sysdate,'yyyy-mm-dd')



select *
from temporary t
where t.createtime between
to_date('2011-3-23 00:00:00', 'YYYY-MM-DD HH24:MI:SS') and
to_date('2011-3-23 23:59:59', 'YYYY-MM-DD HH24:MI:SS')




这个是一天之内,最晚的那条记录


select * from (select * from (select *
from temporary t
where t.createtime between
to_date('2011-3-23 00:00:00', 'YYYY-MM-DD HH24:MI:SS') and
to_date('2011-3-23 23:59:59', 'YYYY-MM-DD HH24:MI:SS')) order by createtime desc)where rownum<2 ;




判断ID的总个数

select count(id) from temporary


while(rs!=null&&rs.next()){
System.out.println("今天的人数:"+rs.getInt(1));
}



判断当天的(今天)id的个数
判断任意一天的id的个数:


select count(id) from (select * from (select * from temporary where trunc(createtime)=trunc(sysdate)) order by createtime desc)";


while(rsl.next()){
System.out.println("总的人数:"+rsl.getInt(1));
}



判断今天前一天的记录:
SELECT * FROM TEMPORARY where trunc(createtime) =trunc(sysdate-1)





判断距今天前十天的记录:
SELECT * FROM TEMPORARY where trunc(createtime) =trunc(sysdate-10)


版权声明:本文为stevenbill原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。