求教,小弟刚学数据库,遇到一个问题,就是求某时间段前后2个小时的数据。举例:2015-01-01 10:00到2015-01-01 16:00,求它们的前2个小时和后2个小时,就是求它们2015-01-01 8:00到2015-01-01 18:00,。这个数据库语句怎么写?
------解决思路----------------------
with m as (
select
to_date('2015-01-01 10:00:00','yyyy-mm-dd hh24:mi:ss') a ,
to_date('2015-01-01 16:00:00','yyyy-mm-dd hh24:mi:ss') b
from dual
)
select
a ,
a - 2 * 1 / 24 as a_new ,
b ,
b + 2 * 1 / 24 as b_new
from m