这个SQL语句怎么写? - Oracle / 基础和管理
这个SQL语句怎么写?
现在有一个表T,里面就3个字段
学生ID(sid)课程(cName)成绩(score)
1 1 75
2 2 90
3 2 60
4 3 89
5 3 80
6 3 70
我现在想知道得到的结果是:每门课程排在前两名的学生的ID,应该怎么写呢?
SQL code:
select k.*
from (select sid,
cname,
score,
rank() over(partition by cname order by score desc) rn
from t) k
where k.rn <= 2
SQL code:
select m.* from
(
select t.* , row_number() over(partition by cName order by score desc) px from tb t
) m
where px <= 2
select m.* from
(
select t.* , (select count(1) from tb where cName = t.cName and score > t.score) + 1 from tb t
) m
where px <= 2
select id,cname from
(select id,cname,rank () over (partition by cname order by score desc) rk
from t)
where rk<=2;
SQL code:
SQL>
SQL> with t as (
2 select 1 sid, 1 cname, 75 score from dual union all
3 select 2, 2, 90 from dual union all
4 select 3, 2, 60 from dual union all
5 select 4, 3, 89 from dual union all
相关问答:
大家好,我现在把oracle服务器上面的原始文件,下载到本机了.我想在本机访问数据库怎么设置啊.是不是类似可以建立一个什么虚拟服务器来实现.请大家出出主意
引用
大家好,我现在把oracle服务器上面 ......
各位大哥,帮个忙。
下个Oracle for vista 版本的安装试试
10G和11G的
http://www.oracle.com/technology/software/products/database/index.html
------------------------------------------- ......
今天做了一个存储过程 环境是SQL2000数据库
大致如下
建立临时表
定义员工游标
循环员工(属于1个公司)
......
我在开发的这个应用并发性比较高,oracle更新数据时候如何处理并发处理呢?各位大侠发表好的观点啊,在线等待!
oracle数据更新时,会自动默认行锁定,楼主不要操心,Oracle对并行处理已经很成熟了
引用
oracle ......
oracle 11g 安装 01092 错误,
日志信息:
[oracle@linux trace]$ vi alert_orcl.log
MMON started with pid=14, OS id=9089
RESETLOGS after incomplete recovery UNTIL CHANGE 522752
Errors in file / ......