题解 | 找出每个学校GPA最低的同学
SELECT device_id, university, gpa FROM ( SELECT device_id, university, gpa, -- 窗口函数,根据university分组,并按照gpa排序 ROW_NUMBER() OVER ( PARTITION BY university ORDER BY gpa ) AS rn FROM user_profile ) t WHERE -- 只取每个分组的第一条 rn = 1;
SELECT device_id, university, gpa FROM ( SELECT device_id, university, gpa, -- 窗口函数,根据university分组,并按照gpa排序 ROW_NUMBER() OVER ( PARTITION BY university ORDER BY gpa ) AS rn FROM user_profile ) t WHERE -- 只取每个分组的第一条 rn = 1;
相关推荐