--根据系统日期查数据(sysdate)
select * from t_br_salesdtl a where a.fstoreid=191 and a.ftime>=to_date(to_char(sysdate-1,'yyyy-mm-dd'),'yyyy-mm-dd ')
--根据给定的日期查数据(eg:2012-07-01至2012-07-03)
第一种方法:
select * from t_br_salesdtl a where a.fstoreid=191 and a.ftime>=to_date('2012-07-01','yyyy-mm-dd')
and a.ftime<=to_date('2012-07-01','yyyy-mm-dd') order by ftime desc
注:用大于和小于取区间值不包含最后指定值
第二种方法:
select * from t_br_salesdtl a where a.fstoreid=191 and a.ftime between to_date('2012-07-01','yyyy-mm-dd')
and to_date('2012-07-01','yyyy-mm-dd') order by ftime desc
以上两种的时间范围其实不包括'2012-07-01'这天的12点之前与之后是不包括的,所以这种查询条件无法查出。
改成如下即可:
第三种方法:
select * from t_br_salesdtl a where a.fstoreid=191 and to_char(a.ftime,'yyyy-mm-dd')>='2012-07-01'
and to_char(a.ftime,'yyyy-mm-dd')<='2012-07-01' order by ftime desc
本文介绍了在SQL中如何根据系统日期或指定日期查询数据的具体方法,包括使用不同的日期范围查询方式及其注意事项。
7911

被折叠的 条评论
为什么被折叠?



