MySQL:按日期时间对记录进行分组,忽略“秒”
我有一个包含数千条记录的表,如下所示:
[Row] ActionTime Score
=======================================
[#1] 2011-08-06 12:30:15 30
[#2] 2011-08-06 12:30:20 50
[#3] 2011-08-06 12:30:47 40
[#4] 2011-08-06 12:40:12 30
[#5] 2011-08-06 12:40:28 10
[#5] 2011-08-06 12:45:12 60
我想以分钟为单位对数据进行分组,并找到每组的最高分数。
所以结果是这样的:
[Row] ActionTime (without "second") Score
========================================================
[#1] 2011-08-06 12:30:00 50
[#2] 2011-08-06 12:40:00 30
[#3] 2011-08-06 12:45:00 60
我如何通过MySQL来做到这一点?
谢谢!
I have a table with thousands of records like this:
[Row] ActionTime Score
=======================================
[#1] 2011-08-06 12:30:15 30
[#2] 2011-08-06 12:30:20 50
[#3] 2011-08-06 12:30:47 40
[#4] 2011-08-06 12:40:12 30
[#5] 2011-08-06 12:40:28 10
[#5] 2011-08-06 12:45:12 60
I want to group the data in minutes and find the maximum score of each group.
So the result is like this:
[Row] ActionTime (without "second") Score
========================================================
[#1] 2011-08-06 12:30:00 50
[#2] 2011-08-06 12:40:00 30
[#3] 2011-08-06 12:45:00 60
How can I do this through MySQL?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不需要选择格式化字段,可以直接在
GROUP BY
中使用它。You don't need to select the formatted field, you can use it directly in
GROUP BY
.