是否有一个 SQL 语句可以 return 来自 groupby 另一列的每个组的 table 列的最大值?

Is there an SQL statement that can return maximum values of a column from a table for each of the groups resulting from groupby another column?

我想知道我们是否可以生成一个 SQL 声明;

  1. 根据给定列 col_1
  2. 将关系 table 中的行分组为 n 组
  3. 根据另一列报告每个组的最大值 col_2。


例如一个数据集包含许多汽车品牌及其各自的成本,因此我们需要一份关于汽车品牌的每个类别的最大成本的报告?喜欢

制作成本
路虎揽胜,50 美元
丰田,30 美元
商业,20 美元

其中 $50、$30 和 $20 分别是 car_make 组 RangeRover、Toyota 和 Merc 中每个组的 cost 列的最大值。

我想象一个 SQL 语句会产生与 pandas 数据帧中的 df.groupby(['Mt'], sort=False)['count'].max() 相同的结果。

有可能:

select col_1, max(col_2)
from table_name
group by col_1