Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/73.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_Sql_Aggregate - Fatal编程技术网

Mysql 选择不同行中的最高值并合并

Mysql 选择不同行中的最高值并合并,mysql,sql,aggregate,Mysql,Sql,Aggregate,我想做的是合并几行数据,以显示为一行。基于行的最高值。因此,只保留具有最高值的记录 由此: 收缩 月 140 12.8 140 12.9 140 13.0 130 8.1 130 8.2 126 1.5 这将是分组,并获得每组的最大值: select ContractID , max(Months) from yourtable group by ContractID GROUP BY,MAX()。请在此处阅读mysql聚合函数

我想做的是合并几行数据,以显示为一行。基于行的最高值。因此,只保留具有最高值的记录

由此:

收缩 月 140 12.8 140 12.9 140 13.0 130 8.1 130 8.2 126 1.5
这将是分组,并获得每组的最大值:

select ContractID , max(Months)
from yourtable
group by ContractID

GROUP BY,MAX()。请在此处阅读mysql聚合函数