Õâ¸ö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
Ïà¹ØÎÊ´ð£º
ÎÒÓжà¸ö±íA B C ½á¹¹ÊÇÒ»ÑùµÄ£¬¶¼ÓÐ2¸ö×Ö¶ÎnameºÍcontent,ÎÒÒªËÑË÷ËùÒÔ±íËùÓÐ×Ö¶ÎÖаüº¬¡°Öйú¡±µÄÄÚÈÝ Õâ¸öSQLÓï¾äÔõôд
ÈçºÎ½«¶à¸ö±íµÄ²éѯ½á¹ûÁ¬³ÉÒ»¸ö±í Õâ¸öSQLÓï¾äÔõôд ±íµÄ½á¹¹ÊÇÒ»ÑùµÄ
ÀýÈç£ ......
½ñÌì×öÁËÒ»¸ö´æ´¢¹ý³Ì »·¾³ÊÇSQL2000Êý¾Ý¿â
´óÖÂÈçÏÂ
½¨Á¢ÁÙʱ±í
¶¨ÒåÔ±¹¤Óαê
Ñ»·Ô±¹¤£¨ÊôÓÚ1¸ö¹«Ë¾)
......
´ÓÊý¾Ý¿âÖвéѯһÕűíµÄÊý¾Ý
select ²¿ÃÅ,ÐÕÃû from tb
ÈçºÎ²ÅÄÜÉú³ÉÏÂÃæµÄxml¸ñʽ
XML code:
<folder state="unchecked" label="È«²¿">
¡¡¡¡ <folder state="unchecked&qu ......
ÈçºÎÔÚSQL2005ÖÐÉ趨¶¨Ê±×÷Òµ£¬±ÈÈç˵¶¨Ê±ÇåÀíijЩ±íµÄÊý¾Ý£¬
»òÕßÊǶ¨Ê±µÄ½«Ä³Ð©±íµÄÊý¾Ýµ¼³öexcel£¡
ÔÚÏߵȴý£¬¼±¼±¼±£¬×îºÃÊÇÏêϸ²½Ö裡
֮ǰÎÒ×öµÄ×÷ÒµÓеãÎÊÌ⣡
°ïUP
²Î¿¼:http://hi.baidu.com/toiota ......