zoukankan      html  css  js  c++  java
  • 学校有多个班级,有语数外多门成绩,按照成绩排序后,找出每个班级语文成绩前五名学生

    我只是记录一下




    select *
    from (select a.*,b.score,
    dense_rank() over(partition by b.classsid order by b.score desc) rn
    from student a,score b
    where a.studentId=b.id and b.classsid=a.classsid)
    where rn<=5


    select *
    from (select a.*,b.score,
    rank() over(partition by b.classsid order by b.score desc) rn
    from student a,score b
    where a.studentId=b.id and b.classsid=a.classsid)
    where rn<=5


    已经验证可以的方案

    select * from (

    select t.id , t.sname , t.china , t.math , t.english ,
    t.glass,t.china + t.math + t.english as total,dense_rank()
    over(partition by t.glass order by t.china + t.math + t.english desc) a from t_score t

    )where a<=5 order by total desc

    还有一种比较熟悉的方案

    Select a.*,(a.china + a.math + a.english) sums
        From t_score a
       Where (Select Count(*)
                From t_score b
               Where a.glass = b.glass
                 And (a.china + a.math + a.english) <
                     (b.china + b.math + b.english)) < 3
       order by  a.glass,sums desc

  • 相关阅读:
    Linux命令笔记
    拆功放板笔记
    从输入 URL 到页面加载完的过程中都发生了什么---优化
    python学习笔记(三)
    python学习笔记(二)
    python学习笔记(一)
    公交wifi运营平台分析
    testNG小试牛刀
    maven小项目注册服务(三)--web模块
    用maven进行测试
  • 原文地址:https://www.cnblogs.com/sloveling/p/5087753.html
Copyright © 2011-2022 走看看