(1) 求出每门课程成绩排名前五名的同学的姓名,分数和课程名:
根据不同的排名方式有三种不同的sql写法:
1.1成绩相同的人排名相同,且排名是连续的。
Sql如下:
当前位置: 数据库>oracle
Oracle的over() 函数使用
来源: 互联网 发布时间:2017-04-11
本文导语: 表及数据: Sql代码 create table STUDENT ( STUDENT_ID NUMBER not null, STUDENT_NAME VARCHAR2(30) not null ) ; alter table STUDENT add primary key (STUDENT_ID); prompt Loading STUDENT... insert into STUDENT (S...
表及数据:
create table STUDENT
(
STUDENT_ID NUMBER not null,
STUDENT_NAME VARCHAR2(30) not null
)
;
alter table STUDENT
add primary key (STUDENT_ID);
prompt Loading STUDENT...
insert into STUDENT (STUDENT_ID, STUDENT_NAME)
values (1, '张三');
insert into STUDENT (STUDENT_ID, STUDENT_NAME)
values (2, '李四');
insert into STUDENT (STUDENT_ID, STUDENT_NAME)
values (3, '王五');
insert into STUDENT (STUDENT_ID, STUDENT_NAME)
values (4, '马六');
insert into STUDENT (STUDENT_ID, STUDENT_NAME)
values (5, '孙七');
insert into STUDENT (STUDENT_ID, STUDENT_NAME)
values (6, '王八');
commit;
create table COURSE
(
COURSE_ID NUMBER not null,
COURSE_NAME VARCHAR2(30)
)
;
alter table COURSE
add primary key (COURSE_ID);
prompt Loading COURSE...
insert into COURSE (COURSE_ID, COURSE_NAME)
values (1, '语文');
insert into COURSE (COURSE_ID, COURSE_NAME)
values (2, '数学');
insert into COURSE (COURSE_ID, COURSE_NAME)
values (3, '英语');
commit;
create table SCORE
(
SCORE_ID NUMBER not null,
STUDENT_ID NUMBER,
COURSE_ID NUMBER,
SCORE NUMBER
)
;
alter table SCORE
add primary key (SCORE_ID);
prompt Loading SCORE...
insert into SCORE (SCORE_ID, STUDENT_ID, COURSE_ID, SCORE)
values (1, 1, 1, 99);
insert into SCORE (SCORE_ID, STUDENT_ID, COURSE_ID, SCORE)
values (2, 1, 2, 98);
insert into SCORE (SCORE_ID, STUDENT_ID, COURSE_ID, SCORE)
values (3, 1, 3, 97);
insert into SCORE (SCORE_ID, STUDENT_ID, COURSE_ID, SCORE)
values (4, 2, 1, 99);
insert into SCORE (SCORE_ID, STUDENT_ID, COURSE_ID, SCORE)
values (5, 2, 2, 97);
insert into SCORE (SCORE_ID, STUDENT_ID, COURSE_ID, SCORE)
values (6, 2, 3, 98);
insert into SCORE (SCORE_ID, STUDENT_ID, COURSE_ID, SCORE)
values (7, 3, 1, 96);
insert into SCORE (SCORE_ID, STUDENT_ID, COURSE_ID, SCORE)
values (8, 3, 2, 95);
insert into SCORE (SCORE_ID, STUDENT_ID, COURSE_ID, SCORE)
values (9, 3, 3, 94);
insert into SCORE (SCORE_ID, STUDENT_ID, COURSE_ID, SCORE)
values (10, 4, 1, 93);
insert into SCORE (SCORE_ID, STUDENT_ID, COURSE_ID, SCORE)
values (11, 4, 2, 92);
insert into SCORE (SCORE_ID, STUDENT_ID, COURSE_ID, SCORE)
values (12, 4, 3, 91);
insert into SCORE (SCORE_ID, STUDENT_ID, COURSE_ID, SCORE)
values (13, 5, 1, 90);
insert into SCORE (SCORE_ID, STUDENT_ID, COURSE_ID, SCORE)
values (14, 5, 2, 89);
insert into SCORE (SCORE_ID, STUDENT_ID, COURSE_ID, SCORE)
values (15, 5, 3, 88);
insert into SCORE (SCORE_ID, STUDENT_ID, COURSE_ID, SCORE)
values (16, 6, 1, 87);
insert into SCORE (SCORE_ID, STUDENT_ID, COURSE_ID, SCORE)
values (17, 6, 2, 86);
insert into SCORE (SCORE_ID, STUDENT_ID, COURSE_ID, SCORE)
values (18, 6, 3, 85);
commit;
select *
from (select s.STUDENT_NAME,
sc.SCORE,
c.COURSE_NAME,
dense_rank() over(partition by c.COURSE_ID order by sc.SCORE desc) drank
from student s, course c, score sc
where s.STUDENT_ID = sc.STUDENT_ID
and c.COURSE_ID = sc.COURSE_ID) t
where t.drank
Oracle 系统变量函数介绍
Oracle 系统变量函数用法指南
Oracle中decode函数的用法
Oracle round()函数与trunc()函数区别介绍
oracle中lpad函数的用法详解
MySQL实现类似Oracle中的decode()函数的功能
Oracle函数substr(str1, pos, [len])
Oracle 函数大全[字符串函数,数学函数,日期函数]第1/4页
SQL中Charindex和Oracle中对应的函数Instr对比
apache通过php的oci函数读取Oracle(字符集ZHS16GBK)时,显示乱码,如何解决?
Oracle Max函数使用中出现的问题
oracle合并列的函数wm_concat的使用详解
请问:在使用oracle数据库作开发时,是使用pro*c作开发好些,还是使用库函数如oci等好一些啊?或者它们有什么区别或者优缺点啊?
c#中oracle to_date函数用法举例
Oracle 函数用法之decode
Oracle过程与函数的区别分析
Oracle层次查询和with函数的使用示例
oracle的nvl函数的使用介绍
c#中oracle的to_date函数使用方法