mysql - 获取一定间隔的数据?
问题描述
我有一个表,我想使用一些查询来获取某些行的属性时间。
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 。我想对查询结果的每个条目都这样做!
解决方案
正式地:
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
(任务不够明确)
推荐阅读
- amazon-web-services - 在 AWS AppSync / AWS Amplify 中保护 GraphQL 模型
- c# - 如何在 OnActionExecutionAsync ASP .Net Core 中记录 HTTP 请求和响应
- android - 如何以编程方式为android重新启动应用程序?
- ios - NSNotificationCenter 发布通知不起作用
- c# - 更改 asp 按钮行为
- mongodb - 所有嵌入文档都符合条件的 Mongoid 查询记录
- python - Sql Alchemy Insert 语句插入失败,但没有错误
- azure - 在 Azure 管道的构建阶段,无法从 docker 映像中的 github 复制工件
- javascript - 外部
React 中的错误信息 - python - 列表中的相同位置?