题解 | #找出每个学校GPA最低的同学#
找出每个学校GPA最低的同学
http://www.nowcoder.com/practice/90778f5ab7d64d35a40dc1095ff79065
此题主要考察开窗函数。
- 首先,根据gpa进行开窗排序
select
device_id,
university,
gpa,
row_number() over(partition by university order by gpa) as ranking
from user_profile
- 然后根据开窗结果,再选出最小序号条件的gpa,结果:
select
device_id,
university,
gpa
from (select
device_id,
university,
gpa,
row_number() over(partition by university order by gpa) as ranking
from user_profile) as t
where ranking=1