静·谧——Last Winner
===========================================================
===========================================================
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

发表评论
标题

在此添加评论
表情符号: smile laughing tongue angry crying sad wassat wink

称呼

邮箱地址(可选)

个人主页(可选)

 authimage


自我介绍
切换风格
新闻聚合
博客日历
文章归档...
最新发表...
最新评论...
最多阅读文章...
最多评论文章...
博客统计...
Blog信息
网站链接...