将日期时间字段分组为块
我有一个带有字段 datestamp (datetime) 的 mysql MyIsam 表,我试图返回过去 3 小时内具有 datestamp 的所有记录,但将其分为 10 个块(因此对于本示例,第一个组将是前 18 分钟)等等...)
有什么想法吗?这在mysql中可能吗?
I have a mysql MyIsam table with a field datestamp (datetime), I am trying to return all records that have a datestamp within the last 3 hours, but group it into 10 chunks (so for this example group one would be the first 18 minutes etc...)
Any ideas? Is this possible in mysql?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为这可能有效:
将差异除以 3 小时间隔(1080 秒)的 1/10。这给出了块 0,1,2...9,其中 0 表示前 18 分钟。
I think this may work:
Devide the difference with 1/10th of the 3 hour interval (1080 sec). This gives chunks 0,1,2...9, where 0 means the first 18 minutes.
当然。因为我并不是真正的 MySQL 专家,所以这是伪代码:
然后你有两列,“年龄”用于限制选择,“组”进一步细分。
Sure. As I'm not really a MySQL expert, this is pseudocode:
Then you have two columns, "age" that you use to limit the selection, and "group" that further subdivides.
像10800这样使用
是3小时内的秒数
use like
10800 is the number of second in 3 hours