sql 前十名

ghostr_ider_lsj 2011-05-12 12:18:37
oracle sql如何获取班级成绩前十的,可能出现有排名相同的情况,比如第二名有两个,第三名有四个这样的情况;
table_name: student;
column: id 标识
score 分数
...全文
513 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
ghostr_ider_lsj 2011-06-10
  • 打赏
  • 举报
回复
谢谢各位,问题已解决,我是按8楼得那种方法。
tiantina 2011-05-13
  • 打赏
  • 举报
回复
select rownum,ename,sal from (select * from emp order by sal desc) where rownum<=10;
Sunkien 2011-05-13
  • 打赏
  • 举报
回复
1、按分数distinct一下,找出第十名分数,再找出大于这个分数的人
liuyyuns 2011-05-12
  • 打赏
  • 举报
回复
select id,score from(select id,score,rownum n from student order by core desc) where n <=10;
liuyyuns 2011-05-12
  • 打赏
  • 举报
回复
你是想查询前十名同学(只有10个),还是想查询前十名的同学(有可能大于10)
304的的哥 2011-05-12
  • 打赏
  • 举报
回复


SQL> with t as(
2 select '21001' id,'杨过' sname,'Oracle' c_name,90 score from dual union all
3 select '20110','张三丰','Oracle',90 from dual union all
4 select '12350','王五','Oracle',88 from dual union all
5 select '14010','李想','Oracle',69 from dual union all
6 select '10012','赵六','C++',87 from dual)
7 select id,sname,c_name,
8 rank() over (partition by c_name order by score desc) rank_1,
9 dense_rank() over (partition by c_name order by score desc) rank_2
10 from t
11 where c_name='Oracle'
12 /

ID SNAME C_NAME RANK_1 RANK_2
----- ------ ------ ---------- ----------
21001 杨过 Oracle 1 1
20110 张三丰 Oracle 1 1
12350 王五 Oracle 3 2
14010 李想 Oracle 4 3
/*
下面的两个函数都能排序,但是有点差别:
rank():出现排名相同的时候,就将排名中的位置留下来
dense_rank():它不将相同位置的名额留下来,而是在下一个排名时使用,
从上面的实例中我们已经看出来了
*/
tangren 2011-05-12
  • 打赏
  • 举报
回复
SELECT *
FROM (SELECT id, scroe, dense_rank() over(ORDER BY score) rn FROM student)
WHERE rn <= 10;
hebo2005 2011-05-12
  • 打赏
  • 举报
回复
用分析函数
row_number() over (
partition by 分组条件 order by 排序条件
) 没有并列,顺序排列
rank 有并列,并跳过下一排名,例如有2个并列第一,下面就是第三名
dense_rank 有并列并且不跳过下一排名,如两个第一,第二有3个,就会显示2个1,3个有2
有关分析函数用法,搜索下
delphisanding1 2011-05-12
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 liuyyuns 的回复:]
select id,score from(select id,score,rownum n from student order by core desc) where n <=10;
[/Quote]

要给你的视图加个别名
jimmylin040 2011-05-12
  • 打赏
  • 举报
回复

select sum(1) over(order by score desc) seq,
code,score
from
(
select '1001' as code,80 as score
from dual
union all
select '1002',81
from dual
union all
select '1003',79
from dual
union all
select '1004',80
from dual
union all
select '1005',95
from dual
union all
select '1006',84
from dual
union all
select '1007',56
from dual
union all
select '1008',95
from dual
union all
select '1009',90
from dual
union all
select '1010',75
from dual
union all
select '1011',60
from dual
union all
select '1012',74
from dual
union all
select '1013',81
from dual
)
谢谢大家的支持,我会陆续上传相关电子书 由于体积较大,本书分两卷压缩,请都下载完再解压! Oracle 11g SQL和PL SQL从入门到精通 pdf格式电子书 下载(一) http://download.csdn.net/source/3268267 Oracle 11g SQL和PL SQL从入门到精通 pdf格式电子书 下载(二) http://download.csdn.net/source/3268312 内容简介   本书是专门为oracle应用开发人员提供的sql和pl/sql编程指南。通过学习本书,读者不仅可以掌握oracle常用工具oracle universal installer、net comfiguration assistant、sql developer、sql*plus的作用及使用方法,而且可以掌握sql语句和pl/sql的各种基础知识和高级特征(记录类型、集合类型、对象类型、大对象类型)。   除了为读者提供编写sql语句和开发pl/sql块的方法外,本书还为应用开发人员提供了一些常用的pl/sql系统包。通过使用这些pl/sql系统包,应用开发人员可以开发出功能更强大的数据库应用程序。本书不仅适合sql和pl/sql初学者,也适合于有经验的oracle应用开发人员。 前言 第一部分 sql和pl/sql相关工具  第1章 在windows 平台上安装oracle database 11g  第2章 配置网络服务名  第3章 使用sql database  第4章 使用sql*plus 第二部分 sql  第5章 sql和pl/sql综述  第6章 简单查询  第7章 sql单行函数  第8章 操纵数据  第9章 复杂查询  第10章 管理常用对象 第三部分 pl/sql  第11章 pl/sql基础  第12章 访问oracle  第13章 编写控制结构  第14章 使用复合数据类型  第15章 使用游标  第16章 异常处理 . 第17章 本地动态sql  第18章 pl/sql过程  第19章 pl/sql函数  第20章 pl/sql包  第21章 触发器  第22章 使用对象类型 第四部分 pl/sql系统包  第23章 使用大对象  第24章 读写os文件  第25章 开发多媒体应用  第26章 开发web应用  第27章 dbms_sq动态sql  第28章 管理统计  第29章 使用数据库资源管理器  第30章 数据加密和解密  第31章 使用调度程序  第32章 使用flashback  第33章 使用重定义联机表  第34章 修正损坏块  第35章 使用日里民挖掘  第36章 使用管道  第37章 使用精细访问控制  第38章 使用精细审计  第39章 使用预警事件  第40章 转换rowid  第41章 其他常用包 习题答案

1,618

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 非技术区
社区管理员
  • 非技术区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧