题解 | #找出每个学校GPA最低的同学#
找出每个学校GPA最低的同学
https://www.nowcoder.com/practice/90778f5ab7d64d35a40dc1095ff79065
SELECT z.device_id, z.university, z.gpa FROM ( SELECT device_id, university, gpa, ROW_NUMBER() OVER(PARTITION BY university ORDER BY gpa) AS ra FROM user_profile) AS z WHERE z.ra = 1;
窗口函数 ROW_NUMBER() OVER(PARTITION BY university ORDER BY gpa)的排名结果不能直接出现在WHERE子句中,需要将窗口函数结果作为子查询(单独的新表),再对新表进行WHERE过滤。