SELECTING * From a Table 但只取最高值的一行

SELECTING * From a Table But Only Taking One Row with Highest Value

假设我有一个 table 具有以下架构

学生

Name SchoolFees
James
James
Paul
Tim

我正在尝试从这个 table 中执行 SELECT *,但要注意的是我只想为每个学生检索一行,其中 SchoolFees 最高。因此,例如,我的查询应该 return

Name SchoolFees
James
Paul
Tim

我该如何构建这个查询?我正在使用 MariaDB

如果您只需要名称和费用的最大值,那么简单的分组依据是最简单的:

select name, max(school_fees) from student group by name;

但是,如果您想要记录最大值为 school_fees 和任何其他字段以及“window 函数”可能会更好。

你可以试试这个

select Name, max(SchoolFees) as SchoolFees from  [Table_Name]
group by Name