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

  • 相关阅读:
    js 正则表达式
    JAVA jdk环境搭建
    VMWareStation10 密钥
    linux xshell jdk hadoop(环境搭建) 虚拟机 安装(大数据搭建环境)
    linux hadoop jdk虚拟机下配置
    Linux shell基础(四)
    Linux shell基础(二)
    Linux shell基础(三)
    Linux shell基础(一)
    html
  • 原文地址:https://www.cnblogs.com/sloveling/p/5087753.html
Copyright © 2011-2022 走看看