获得4次中间距离

时间:2016-10-21 16:37:15

标签: mysql select range

enter image description here

我每5分钟有2个表存储数据,如何在表1时间范围内进行查询加入并选择表2的time_begin和time_end?

例如:

table1: time_begin: 20:01:00, time_end: 20:24:00
table 2: time_begin: 20:00:00, time_end: 20:25:00

=>我需要选择time_begin:20:01:00,time_end:20:24:00

table1: time_begin: 20:01:00, time_end: 20:24:00
table2: time_begin: 20:02:00, time_end: 20:25:00

=>我需要选择time_begin:20:02:00,time_end:20:24:00

table1: time_begin: 20:01:00, time_end: 20:24:00
table2: time_begin: 20:02:00, time_end: 20:23:00

=>我需要选择time_begin:20:02:00,time_end:20:23:00

1 个答案:

答案 0 :(得分:1)

GREATEST(t1.time_begin, t2.time_begin)
LEAST(t1.time_end, t2.time_end)