MYSQL时间间隔及按时间间隔求和数据

发布于 2024-12-25 18:38:57 字数 582 浏览 1 评论 0原文

我有一个表,它将根据一分钟的间隔记录所有数据。现在我想检索记录,如果给定的时间间隔为 2 分钟,则应添加间隔为 2 分钟的完整记录并显示在屏幕上。 假设表是:

日期 |时间 |数据

2011年11月20日| 9:00 | 2

2011年11月20日| 9:01 | 3

2011年11月20日| 9:02 | 6

2011年11月20日| 9:03 | 9:03 2

2011年11月20日| 9:04 | 9:04 1

2011年11月20日| 9:05 | 9:05 4

2011年11月20日| 9:06 | 9:06 4

因此,如果开始日期选择为 20-11-2011,开始时间为 9:01,间隔为 2 分钟,则该表应为:

日期 |时间 |数据

2011年11月20日| 9:01 | 9

2011年11月20日| 9:03 | 9:03 3

2011年11月20日| 9:05 | 9:05 8

请帮我解决这个问题,我是 mysql 和 php 的新手

:时间是时间戳类型..

I have a table which will log all the data based on one minute interval. Now I want to retrieve the records such that, if the time interval is given 2 minutes it should add the complete records with 2 minutes interval and show on screen..
Suppose the Table is:

Date | Time | Data

20-11-2011| 9:00 | 2

20-11-2011| 9:01 | 3

20-11-2011| 9:02 | 6

20-11-2011| 9:03 | 2

20-11-2011| 9:04 | 1

20-11-2011| 9:05 | 4

20-11-2011| 9:06 | 4

So, if the start date is selected as 20-11-2011 and start time as 9:01 and interval as 2 minutes, then the table should be:

Date | Time | Data

20-11-2011| 9:01 | 9

20-11-2011| 9:03 | 3

20-11-2011| 9:05 | 8

Kindly help me with this, I'm new to mysql and php

Here: Time is a Timestamp type..

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

神也荒唐 2025-01-01 18:38:57

这应该有效:

SELECT SUM(`data`), MIN(`time)
FROM tblname
WHERE `time` >= '9:01' AND `date` = '2011-11'20
GROUP BY FLOOR((TIME_TO_SEC(`time`) - TIME_TO_SEC('9:01')) / 60 / 2)

This should work:

SELECT SUM(`data`), MIN(`time)
FROM tblname
WHERE `time` >= '9:01' AND `date` = '2011-11'20
GROUP BY FLOOR((TIME_TO_SEC(`time`) - TIME_TO_SEC('9:01')) / 60 / 2)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文