3,491
社区成员
发帖
与我相关
我的任务
分享
select *
from tb_info
where (sid, cid) in
(
select aa.sid, aa.cid
from (
select a.sid, a.cid, dense_rank() over(partition by cid order by score desc) rn1
from tb_info a
where a.cname = '语文'
) aa
where rn1 <=10 and
not exists
(
select 1
from (
select b.sid, b.cid, dense_rank() over(partition by cid order by score) rn2
from tb_info b
where b.cname = '数学'
) bb
where aa.sid = bb.sid and aa.cid = bb.cid and rn2<=10
)
);
select * from tb_info
where (sid, cid) in
(
select aa.sid, aa.cid
from (
select a.sid, a.cid, dense_rank() over(partition by cid order by score desc) rn1
from tb_info a
where a.cname = '语文'
) aa,
( select b.sid, b.cid, dense_rank() over(partition by cid order by score) rn2
from tb_info b
where b.cname = '数学'
) bb
where aa.sid = bb.sid and aa.cid = bb.cid and rn1<=10 and rn2 >10
);
select *
from
(select a.*
,b.cname cname2
,b.score score2
,dense_rank() over(partition by a.cid order by a.score desc) rn1
,dense_rank() over(partition by a.cid order by b.score) rn2
from tb_info a,tb_info b
where a.sid=b.sid and a.cid=b.cid
and a.cname='语文'
and b.cname='数学'
)a
where a.rn1<=10 and a.rn2>10
;
SELECT SID,cid,sname
FROM(
SELECT SID,cid,sname,
rank()OVER(PARTITION BY cid ORDER BY max(decode(cname,'语文',score)) DESC)rk1,
rank()OVER(PARTITION BY cid ORDER BY max(decode(cname,'数学',score)))rk2
FROM tb_info
WHERE cname IN('语文','数学')
GROUP BY SID,cid,sname
)
WHERE rk1<=10
AND rk2>10;
with sx as
(select * from(select sid, cid, dense_rank() over(partition by sid,cid order by score desc)sxpm
from tb_info
where cname = '数学') where sxpm<=10)
select * from (select t.*,dense_rank() over(partition by t.sid,t.cid order by t.score desc)ywpm
from tb_info t where
t.cname='语文' and not exists
(select null from sx where sx.sid=t.sid and sx.cid=t.cid)) where ywpm<=10