方法一:left join
select p.device_id, u.university, u.gpa
from (select university, min(gpa) as gpa from user_profile group by university) u
left join user_profile p
on u.university = p.university and u.gpa = p.gpa
order by u.university;
方法二:join
select a.device_id, a.university, a.gpa
from user_profile a
join
(select university,min(gpa) gpa
from user_profile
group by university
) b
on
a.gpa = b.gpa and a.university = b.university
order by a.university;
方法三:子查询
select device_id, university, gpa
from user_profile u
where gpa in (
select min(gpa) from user_profile
where university = u.university
)
order by university