日期:2014-05-17  浏览次数:21101 次

这样写sql是不是少一天数据?
select * from A
where finish_time>= date'2013-1-1'
and finish_time<= date '2013-1-31'

是不是少2013-1-31这天的数据?
因为finish_time 是date格式,date '2013-1-31'应该是这天的2013:1:13:00:00时间。
第三行不是不要改成and finish_time< date '2013-2-1'。
求高手。

------解决方案--------------------
yes。
------解决方案--------------------
因为finish_time 是date格式,date '2013-1-31'应该是这天的2013:1:13:00:00时间。
第三行不是不要改成and finish_time< date '2013-2-1'。

是这样的,
类似的写法还有  
and finish_time<= to_date('2013-1-31 23:59:59','yyyy-mm-dd hh24:mi:ss')

and trunc(finish_time)<= date '2013-1-31'--不提倡
------解决方案--------------------
如楼上说的,你直接把条件改成 and finish_time<= to_date('2013-1-31 23:59:59','yyyy-mm-dd hh24:mi:ss') 就包括31的了