MySQL Group By 自定义时间戳
我想从按日期分组的数据库中获取结果。生成的元组应按日期分组,日期范围为上午 5 点到凌晨 5 点。换句话说,截止时间应该是凌晨 5 点,而不是午夜 12 点。我可以执行 GROUP BY DAY(timestamp)
按正常日期进行分组,但是如果我必须改变时间并且每条记录应从上午 5 点到凌晨 5 点分组怎么办?我应该如何更改查询?谢谢 ?
I want to get results from the database which is grouped by date. The resulting touples should be grouped by date which ranges from 5 am to 5 am. In other words the cutoff should be on 5 am and not midnight 12 am. I can do GROUP BY DAY(timestamp)
to group by normal day but what if I have to vary the time and each records should be grouped from 5 am to 5 am ? How should I change the query ? Thanks ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需从每个日期时间值中减去 5 小时,然后将其转换为日期即可。然后您可以根据结果进行分组。
Simply subtract 5 hours from each datetime value you have, and then convert it to a date. Then you can group by the result.