要查找最新的时间戳,请首先使用比较运算符排除将来的时间戳。接下来,通过从所需时间戳中减去可能的时间戳候选,以最小间隔进行排序。要获取最新结果,请限制为1。
要使table2
val列与table1列一起显示,您只需要在子查询中为table2运行相同的代码。
SELECt update_time AS time, id1, id2, val, ( SELECT val from table2 WHERe '2004-10-19 10:04:00' >= update_time ORDER BY '2004-10-19 10:04:00' - update_time LIMIT 1)FROM table1 WHERe '2004-10-19 10:04:00' >= update_timeORDER BY '2004-10-19 10:04:00' - update_timeLIMIT 1;



