把任务拆解开来。

第一步是找到gpa最小的学校以及对应的gpa作为一张表。

第二步是把user_profile表和刚才找到的表join条件就是学校相同,gpa相同。 最后要把结果对学校排序。

select 
a.device_id, 
a.university,
a.gpa
from user_profile as a
join
(
    select
    min(gpa) as gpa, university
    from user_profile
    group by university
) as b
on a.gpa = b.gpa 
and a.university = b.university
order by b.university;