gpt4 book ai didi

MySQL : group records by datetime ignoring the "seconds"

转载 作者:行者123 更新时间:2023-11-29 01:18:27 24 4
gpt4 key购买 nike

我有一个包含数千条记录的表:

[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 执行此操作?

谢谢!

最佳答案

select 
date_format(actiontime,'%Y-%m-%d %H:%i:00') as act_time,
max(score) as greater
from table
group by act_time

关于MySQL : group records by datetime ignoring the "seconds",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6981973/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com