重温一下聚合函数:sum(),count(),avg(),max(),min()...
分组group by原则上需要与聚合函数配合使用,如果想先排序再分组,order by需要充当聚合函数的作用,如:
select id,max(salary) from (select * from tableName order by id desc) group by department
看起来略微繁杂,如果用distinct实现:
select id,max(salary),distinct department from tableName order by id desc