题解 | #找出每个学校GPA最低的同学#

找出每个学校GPA最低的同学

http://www.nowcoder.com/practice/90778f5ab7d64d35a40dc1095ff79065

方法1:用子循环,因为device与gpa对应,所以不能直接用聚合函数,考虑使用子循环.让学校与min(gpa)一一对应

select device_id,university,gpa from user_profile
    where (gpa,university) in(select min(gpa),university from user_profile
            group by university)
order by university

方法2:使用窗口函数,先对每个学校的成绩进行排序,再选出最低的,注意sql中的窗口函数不能直接命名为rank

    select device_id,university,gpa,
     row_number()over(partition by university order by gpa) as t_rank
    from user_profile
)t
where t_rank=1
order by university
全部评论

相关推荐

07-02 10:44
门头沟学院 C++
码农索隆:太实诚了,告诉hr,你能实习至少6个月
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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