题解 | 找出每个学校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











全部评论

相关推荐

02-04 17:01
南昌大学 Java
牛客96763241...:拿插件直接投就完了,这玩意看运气的
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务