select * from points where add_time between sysdate and sysdate-7;
select * from points where to_char(add_time,'yyyymmdd') >to_char(sysdate-7,'yyyymmdd')
select * from points where to_char(add_time,'yyyymmdd') between to_char(sysdate-6,'yyyymmdd') and to_char(sysdate,'yyyymmdd') 取範圍
谢谢楼上各位大侠啊 已经解决了 我是这样写的select p.* from ccc_points p where p.add_time < to_date(substr(to_char(sysdate-1,'yyyy-MM-dd'),1,10) || '23:59:59','yyyy-MM-dd HH24:mi:ss') and p.add_time >to_date(substr(to_char(sysdate-8,'yyyy-MM-dd'),1,10) || '00:00:01','yyyy-MM-dd HH24:mi:ss')
如果字段是时间类型,直接比较就是了。 干嘛又to_char 又 to_date
没必要这么麻烦的,sysdate是从2011-11-14 00:00:00 到2011-11-14 23:59:59的 用between and 就好了,楼上几个方法简便多了
select *
from points
where add_time between sysdate and sysdate-7;
and to_char(sysdate,'yyyymmdd')
取範圍
and p.add_time >to_date(substr(to_char(sysdate-8,'yyyy-MM-dd'),1,10) || '00:00:01','yyyy-MM-dd HH24:mi:ss')
用between and 就好了,楼上几个方法简便多了