取各学科平均分排名前10的学生 语句问题 到底哪里错了??

michaelgy 2008-03-06 10:32:44
学生考试, 一年考试N次, 取各学科平均分排名前10的学生

select a.* from
(
select studentid, avg(score) as score1, subject from tableA
group by studentid , subject
) a
where
(
select count(1) from (
select studentid, avg(score) as score1, subject from tableA
group by studentid , subject )b
where a.studentid = b.studentid and a.subject = b.subject and b.score1> a.score1) < 10
)
order by a.subject , a.score1 desc

...全文
240 20 打赏 收藏 转发到动态 举报
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
meiZiNick 2008-04-30
  • 打赏
  • 举报
回复
以后需再关注,现在先帮你顶一下
pccastle 2008-04-27
  • 打赏
  • 举报
回复
哈哈··我也来··jf
pccastle 2008-04-27
  • 打赏
  • 举报
回复
ding
zgmeimei 2008-03-22
  • 打赏
  • 举报
回复
路过,顶一下,支持LZ

------------------------------------------------

给灌水区的兄弟们推荐一个养眼的网站,嘿嘿。
http://www.zgmeimei.cn
HelloWorld_001 2008-03-20
  • 打赏
  • 举报
回复
[Quote=引用 9 楼 hz89cool 的回复:]
row_number()是什么啊?OVER 是什么.他们怎么用啊?
[/Quote]
这个是分析函数。
自己去查用法
认真读书 2008-03-20
  • 打赏
  • 举报
回复
顶。。不知道。。网上搜一下,就全明白了
wzjpsq 2008-03-20
  • 打赏
  • 举报
回复
up
liuyann 2008-03-09
  • 打赏
  • 举报
回复

sohome 2008-03-09
  • 打赏
  • 举报
回复
学到东西
hz89cool 2008-03-08
  • 打赏
  • 举报
回复
row_number()是什么啊?OVER 是什么.他们怎么用啊?
liuyann 2008-03-08
  • 打赏
  • 举报
回复

zjkk1011 2008-03-07
  • 打赏
  • 举报
回复
top?
doer_ljy 2008-03-07
  • 打赏
  • 举报
回复
fosjos 正解
使用rank over(...)为每个合计加上科目内的序号。
然后再外层循环中过滤掉序号大于10的。
doer_ljy 2008-03-07
  • 打赏
  • 举报
回复
fosjos的正解
使用partition by 按照科目分组在分组内使用over的Order by对成绩均值排序用rank给她们加上序号,然后在父查询中过滤掉rownum大于10的记录。
tanjun132 2008-03-06
  • 打赏
  • 举报
回复
top oracle传说中不可以用吧
dawugui 2008-03-06
  • 打赏
  • 举报
回复
--明白了,是一个人一年当中这个学科的平均分.
select t.* from 
(
select subject , studentid , avg(score) score from tb group by subject , studentid
) tb t
where score in
(
select top 10 score from (select subject , studentid , avg(score) score from tb group by subject , studentid) m where subject=t.subject order by score desc
)
order by subject , score desc
dawugui 2008-03-06
  • 打赏
  • 举报
回复
各学科平均分排名前10的学生 ?

应该是各学科得分排名前10的学生吧?

select * from tb t
where score in
(
select top 10 score from tb where subject=t.subject order by score desc
)
order by subject , score desc
fosjos 2008-03-06
  • 打赏
  • 举报
回复
select t.* from
(
select subject , studentid , avg(score) score
,row_number() over (partition by subject order by avg(score) desc) as num
from tb group by subject , studentid
)t
where num<=10
sparrow_liu 2008-03-06
  • 打赏
  • 举报
回复
top ? oracle能用么?

1,618

社区成员

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

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