Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/unix/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MySQL:按日期时间对记录进行分组,忽略;秒“;_Mysql_Date_Group By - Fatal编程技术网

MySQL:按日期时间对记录进行分组,忽略;秒“;

MySQL:按日期时间对记录进行分组,忽略;秒“;,mysql,date,group-by,Mysql,Date,Group By,我有一个包含数千条记录的表,如下所示: [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]

我有一个包含数千条记录的表,如下所示:

[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
SELECT * FROM table_name
GROUP BY date_format(datetime_field, '%Y-%m-%d %H:%i:00');

值得注意的是,如果使用printf格式化查询(或此函数的某些派生函数),请将转义ie“%Y”放入“%%Y”(或者printf将尝试按“%%”将参数放入该位置,并将其视为普通字符串)。