日期:2014-05-17 浏览次数:20927 次
--写一个timestamp的 SELECT * FROM temp WHERE id = (SELECT ok_id FROM (SELECT t.*, lag(id) over(ORDER BY login_time) prev_id, lead(id) over(ORDER BY login_time) next_id, CASE WHEN (scn_time - lag(scn_time) over(ORDER BY login_time)) - (lead(scn_time) over(ORDER BY login_time) - scn_time) < 0 THEN lag(id) over(ORDER BY login_time) ELSE lead(id) over(ORDER BY login_time) END ok_id FROM (SELECT id, NAME, login_time, timestamp_to_scn(login_time) scn_time FROM temp) t) WHERE login_time = to_timestamp('2010/3/23 16:13:36.397000', 'yyyy/mm/dd hh24:mi:ss.ff'));