进行差值比较即可: select case when 时间1-选择时间>时间2-选择时间 then 时间2 else 时间1 from gpsdata20121219 ;
select case when 时间1-选择时间>时间2-选择时间 then 时间2 else 时间1 end from gpsdata20121219 ; 少了end
select case when (To_date('2012-12-19 08:17:00','yyyy-mm-dd hh24-mi-ss'))-(To_date('2012-12-19 08:18:00','yyyy-mm-dd hh24-mi-ss'))>(To_date('2012-12-19 08:18:59','yyyy-mm-dd hh24-mi-ss'))-(To_date('2012-12-19 08:18:00','yyyy-mm-dd hh24-mi-ss')) then '2012-12-19 08:18:59' else '2012-12-19 08:17:00' end from gpsdata20121219 ; 我这样写怎么一直循环了
select case when (To_date('20121219081700', 'yyyymmddhh24miss')) - (To_date('20121219081800', 'yyyymmddhh24miss')) > (To_date('20121219081859', 'yyyymmddhh24miss')) - (To_date('20121219081800', 'yyyymmddhh24miss')) then '2012-12-19 08:18:59' else '2012-12-19 08:17:00' end from dual
with A as ( select to_date('2013-01-01','yyyy-mm-dd') as times from dual union all select to_date('2013-03-01','yyyy-mm-dd') as times from dual union all select to_date('2013-07-01','yyyy-mm-dd') as times from dual) select * from ( select to_date('2013-02-01','yyyy-mm-dd') - times 时间差,a.* from A order by abs(时间差) asc ) where rownum =1
select * from tab t where abs(t.datecol -userdate) = ( select min(abs(t1.datecol -userdate)) from tab t1 having min(abs(t1.datecol -userdate)) )
select * from gpsdata20121219 t where abs(to_date(t.time...) -To_date('20121219081700', 'yyyymmddhh24miss')) = ( select min(abs(to_date(t1.time...) -To_date('20121219081700', 'yyyymmddhh24miss'))) from gpsdata20121219 t1 having min(abs(to_date(t1.time...) -To_date('20121219081700', 'yyyymmddhh24miss'))) ) to_date(t1.time...) 是time转换为datetime的方法,我很少用,自己补充一下
select case when 时间1-选择时间>时间2-选择时间 then 时间2 else 时间1 from gpsdata20121219 ;
少了end
select case when (To_date('2012-12-19 08:17:00','yyyy-mm-dd hh24-mi-ss'))-(To_date('2012-12-19 08:18:00','yyyy-mm-dd hh24-mi-ss'))>(To_date('2012-12-19 08:18:59','yyyy-mm-dd hh24-mi-ss'))-(To_date('2012-12-19 08:18:00','yyyy-mm-dd hh24-mi-ss')) then '2012-12-19 08:18:59' else '2012-12-19 08:17:00' end from gpsdata20121219 ;
我这样写怎么一直循环了
when (To_date('20121219081700', 'yyyymmddhh24miss')) -
(To_date('20121219081800', 'yyyymmddhh24miss')) >
(To_date('20121219081859', 'yyyymmddhh24miss')) -
(To_date('20121219081800', 'yyyymmddhh24miss')) then
'2012-12-19 08:18:59'
else
'2012-12-19 08:17:00'
end
from dual
union all
select to_date('2013-03-01','yyyy-mm-dd') as times from dual
union all
select to_date('2013-07-01','yyyy-mm-dd') as times from dual)
select * from (
select to_date('2013-02-01','yyyy-mm-dd') - times 时间差,a.* from A order by abs(时间差) asc ) where rownum =1
where abs(t.datecol -userdate) = (
select min(abs(t1.datecol -userdate))
from tab t1
having min(abs(t1.datecol -userdate))
)
where abs(to_date(t.time...) -To_date('20121219081700', 'yyyymmddhh24miss')) = (
select min(abs(to_date(t1.time...) -To_date('20121219081700', 'yyyymmddhh24miss')))
from gpsdata20121219 t1
having min(abs(to_date(t1.time...) -To_date('20121219081700', 'yyyymmddhh24miss')))
)
to_date(t1.time...) 是time转换为datetime的方法,我很少用,自己补充一下