oracle 查询各科前3名_ORACLE分科目统计每科前三名的学生的语句

2023-10-07 07:59

本文主要是介绍oracle 查询各科前3名_ORACLE分科目统计每科前三名的学生的语句,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

成绩表 score(student_no,Subject_no,Score)分别为学号,课程号,成绩

查询出每科的前三名学生的学号

创建表并插入测试数据

create table score(student_no varchar2(3),Subject_no varchar2(20),Score number);insert into score values('001','语文',70);insert into score values('001','数学',60);insert into score values('001','英语',90);insert into score values('002','语文',78);insert into score values('002','数学',67);insert into score values('002','英语',80);insert into score values('003','语文',89);insert into score values('003','数学',60);insert into score values('003','英语',97);insert into score values('004','语文',50);insert into score values('004','数学',67);insert into score values('004','英语',70);insert into score values('005','语文',79);insert into score values('005','数学',65);insert into score values('005','英语',79);insert into score values('006','语文',78);insert into score values('006','数学',56);insert into score values('006','英语',87);commit;

第一种查询:

查询的sql语句:

select *from (select s.*,row_number() over(partition by s.subject_no order by s.score desc) pfrom score s)
where p <= 3

结果如下

第二种查询:

查询的sql语句

select *from (select s.*,rank() over(partition by s.subject_no order by s.score desc) pfrom score s)where p <= 3

结果如下

区别

row_number:不管排名是否有相同的,都按照顺序1,2,3…..n
rank:排名相同的名次一样,同一排名有几个,后面排名就会跳过几次
dense_rank:排名相同的名次一样,且后面名次不跳跃

这篇关于oracle 查询各科前3名_ORACLE分科目统计每科前三名的学生的语句的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/157080

相关文章

hdu1496(用hash思想统计数目)

作为一个刚学hash的孩子,感觉这道题目很不错,灵活的运用的数组的下标。 解题步骤:如果用常规方法解,那么时间复杂度为O(n^4),肯定会超时,然后参考了网上的解题方法,将等式分成两个部分,a*x1^2+b*x2^2和c*x3^2+d*x4^2, 各自作为数组的下标,如果两部分相加为0,则满足等式; 代码如下: #include<iostream>#include<algorithm

活用c4d官方开发文档查询代码

当你问AI助手比如豆包,如何用python禁止掉xpresso标签时候,它会提示到 这时候要用到两个东西。https://developers.maxon.net/论坛搜索和开发文档 比如这里我就在官方找到正确的id描述 然后我就把参数标签换过来

flume系列之:查看flume系统日志、查看统计flume日志类型、查看flume日志

遍历指定目录下多个文件查找指定内容 服务器系统日志会记录flume相关日志 cat /var/log/messages |grep -i oom 查找系统日志中关于flume的指定日志 import osdef search_string_in_files(directory, search_string):count = 0

hdu4267区间统计

题意:给一些数,有两种操作,一种是在[a,b] 区间内,对(i - a)% k == 0 的加value,另一种操作是询问某个位置的值。 import java.io.BufferedInputStream;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import

hdu4417区间统计

给你一个数列{An},然后有m次查询,每次查询一段区间 [l,r] <= h 的值的个数。 import java.io.BufferedInputStream;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamRead

hdu3333区间统计

题目大意:求一个区间内不重复数字的和,例如1 1 1 3,区间[1,4]的和为4。 import java.io.BufferedInputStream;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;

实例:如何统计当前主机的连接状态和连接数

统计当前主机的连接状态和连接数 在 Linux 中,可使用 ss 命令来查看主机的网络连接状态。以下是统计当前主机连接状态和连接主机数量的具体操作。 1. 统计当前主机的连接状态 使用 ss 命令结合 grep、cut、sort 和 uniq 命令来统计当前主机的 TCP 连接状态。 ss -nta | grep -v '^State' | cut -d " " -f 1 | sort |

ural 1026. Questions and Answers 查询

1026. Questions and Answers Time limit: 2.0 second Memory limit: 64 MB Background The database of the Pentagon contains a top-secret information. We don’t know what the information is — you

Mybatis中的like查询

<if test="templateName != null and templateName != ''">AND template_name LIKE CONCAT('%',#{templateName,jdbcType=VARCHAR},'%')</if>

Oracle type (自定义类型的使用)

oracle - type   type定义: oracle中自定义数据类型 oracle中有基本的数据类型,如number,varchar2,date,numeric,float....但有时候我们需要特殊的格式, 如将name定义为(firstname,lastname)的形式,我们想把这个作为一个表的一列看待,这时候就要我们自己定义一个数据类型 格式 :create or repla