首页 > 解决方案 > 获取一定间隔的数据?

问题描述

我有一个表,我想使用一些查询来获取某些行的属性时间。

select  view,time from new_table where type="someType";

现在,对于上述查询结果中的每个时间条目,我想从另一个表中获取记录,该表在此时间之前的最后 1 分钟内发生。

Result of query
 view1,14:06:45
 view2,14:07:45
 view3,14:08:45
 view4,14:09:45



fetchDataTable should give this output for the data view1,14:06:45

some1,Touchl,1151,547,2020/6/25, 14:05:45,
some2,TouchFl,1151,547,2020/6/25,14:06:14,
some3,TouchFl,1151,547,2020/6/25,14:06:20,
some4,TouchFl,1151,547,2020/6/25,14:06:24,

我想fetchDataTable从 time 获取 table say 中的条目14:05:45 to 14:06:45。表 fetchDataTable 也有属性 time 。我想对查询结果的每个条目都这样做!

标签: mysqlsqldatabase

解决方案


正式地:

SELECT t1.time, t2.*
FROM t1
JOIN t2 ON t2.time BETWEEN t1.time - INTERVAL 1 MINUTE AND t1.time
WHERE t1.type = 'someType'

或者

SELECT t1.type, t1.time, t2.*
FROM t1
JOIN t2 ON t2.time BETWEEN t1.time - INTERVAL 1 MINUTE AND t1.time

(任务不够明确)


推荐阅读