===========================================================
===========================================================
显示每个班分数前的15%名的同学名单
作者: lastwinner(http://lastwinner.itpub.net)
发表于: 2005.11.07 22:05
分类:
Oracle
出处: http://lastwinner.itpub.net/post/7102/45131
---------------------------------------------------------------
create table a
(class varchar2(8),
student varchar2(100),
score number(3)
)
class 代表班,应该有一班,二班,三班...
student学生
score分数
有多个班,每个班有多名同学
现在想查询并显示每个班分数前的15%名的同学名单,请问该如何写查询语句select class,student,score from
(
select class,student,score,
rank()over(partition by class order by score desc)/count(*)over(partition by class) ratio
from a
)
where ratio<=0.15
lastwinner
发表于:2005.11.07 22:05
::分类:
(
Oracle
)
::阅读:(1806次)
::
评论
(4)

re: 显示每个班分数前的15%名的同学名单
[回复]
我新手,在论坛上看到你好多热心的帖子,就来取经了。
oracle中有个emp表,表中有部门号,薪水等字段。查询部门收入前两名的雇员。
select * from emp a where (select count(*) from emp b where a.deptno=b.deptno and b.sal>a.sal)
天地沙鸥
评论于: 2005.11.12 00:15

re: 显示每个班分数前的15%名的同学名单
[回复]
不好意思,上面的丢失了几个字母,应该是
select * from emp a where (select count(*) from emp b where a.deptno=b.deptno and b.sal>a.sal)
天地沙鸥
评论于: 2005.11.12 00:18

re: 显示每个班分数前的15%名的同学名单
[回复]
没办法,怎么老丢失后面的
尾巴应该是 a.sal)
天地沙鸥
评论于: 2005.11.12 00:20

re: 显示每个班分数前的15%名的同学名单
[回复]
真服了,又丢了。汉字吧,看他再丢
在上面补上“小余1”
天地沙鸥
评论于: 2005.11.12 00:21