select device_id,university,gpa from user_profile where (university,gpa) in (select university,min(gpa) from user_profile group by university) order by university ; select device_id, university, gpa from ( select *, row_number() over (partition by university order by gpa) as rn from user_profile ) as univ_min where rn=1 order by university;
第一种是我抠破脑袋抠出来的,
第二种是我看大佬们用窗口函数,恍然大悟,我怎么忘了这么有用的函数呢,小用了一下,不过我还是比较喜欢第一种简单一点。

京公网安备 11010502036488号