题解 | 找出每个学校GPA最低的同学
找出每个学校GPA最低的同学
https://www.nowcoder.com/practice/90778f5ab7d64d35a40dc1095ff79065
/* select
device_id,
university,
gpa
from
user_profile u1
where
gpa = (
select min(gpa)
from user_profile u2
where u2.university = u1.university
)
order by
university */
# 对每一个学校的gpa求最小值,运用子查询where筛选每一学校然后求最小gpa,与最小gpa相等的外层查询的gpa即为所求。
select
device_id,
university,
gpa
from
(
select
device_id,
university,
gpa,
row_number() over(partition by university order by gpa) as rn
from
user_profile
) t
where
rn = 1
order by university