ʹÓÃSQLÓï¾äÕÒµ½±íÖÐijÁеĵڼ¸Ãû
SQL> select * from t1;
ID AGE
---------- ----------
1 20
2 19
3 19
4 21
5 22
6 27
6 rows selected.
ÏÖÔÚÒªÇóÕÒ³ö±íÖеÚÈýÄêÇáµÄѧÉú
·½·¨1
µÚÈýÄêÇᣬҲ¾ÍÒâζ×ÅÖ»ÓÐÁ½¸öÈ˱ÈËûС
SQL> select t11.*
2 from t1 t11
3 where 2=(select count(*) from t1 t22 where t11.age>t22.age);
ID AGE
---------- ----------
1 20
·½·¨2
ʹÓô°¿Úº¯Êý
SQL> select id,age
2 from
3 (
4 select id,age,
5 dense_rank() over(order by age) dr
6 from t1
7 )
8 where dr=3;
ID AGE
---------- ----------
4 21
Ææ¹ÖÁË£¬ÕâÀï½á¹ûΪʲô²»Ò»ÑùÄØ£¿»ØÍ·¿´Ò»Ï±íÖеÄÊý¾Ý£¬ÓÐÁ½Ìõage=19µÄÊý¾Ý£¬Õâ¾ÍÊÇÔÒò¡£ÏÂÃæ»»rank
SQL> select id,age
2 from
3 (
4 select id,age,
5 rank() over(order by age) dr
6 from t1
7 )
8 where dr=3;
 
Ïà¹ØÎĵµ£º
ϵͳ»·¾³£ºWindows 7
Èí¼þ»·¾³£ºVisual C++ 2008 SP1 +SQL Server 2005
±¾´ÎÄ¿µÄ£º±àдһ¸öº½¿Õ¹ÜÀíϵͳ
ÕâÊÇÊý¾Ý¿â¿Î³ÌÉè¼ÆµÄ³É¹û£¬ËäÈ»³É¼¨²»¼Ñ£¬µ«ÊÇ×÷ΪÎÒÓÃVC++ ÒÔÀ´±àдµÄ×î´ó³ÌÐò»¹ÊÇ´«µ½ÍøÉÏ£¬ÒÔ¹©²Î¿¼¡£ÓÃVC++ ×öÊý¾Ý¿âÉè¼Æ²¢²»ÈÝÒ×£¬µ«Ò²²»ÊDz»¿ÉÄÜ¡£ÒÔÏÂÊÇÎҵijÌÐò½çÃ棬ºóÃæ ......
½ñÌìÖÕÓÚÖªµÀSQL 2005 ÔõôÓÃÁË£¬¸Ð¾õÒÔÇ°Ì«ÀÁÁË£¬Ã÷Ã÷ÏëÖªµÀµÄ¶«Î÷¿ÉÊÇÒòΪÒѾÓÐsql2000¾ÍÀÁµÃ²é¡£ÖªÊ¶ÕⶫÎ÷ÊÇÈÕ»ýÔÂÀ۵ģ¬ÕæÕýµ½ÓõÄʱºò²ÅÈ¥²¹¾ÍÒѾÍíÁË¡£
ÒÔÇ°°²×°VS2005µÄʱºò¾Í¿´µ½°²×°ÍêÁËÒÔºó»áÓÐÒ»¸öSQL2005£¬¿ÉÊÇ×Ô¼º²»»áÓã¬ÄǸöʱºòÖ» ......
1. ¶ÔÓÚPHP magic_quotes_gpc=onµÄÇé¿ö£¬ ÎÒÃÇ¿ÉÒÔ²»¶ÔÊäÈëºÍÊä³öÊý¾Ý¿âµÄ×Ö·û´®Êý¾Ý×÷
addslashes()ºÍstripslashes()µÄ²Ù×÷,Êý¾ÝÒ²»áÕý³£ÏÔʾ¡£ Èç¹û´ËʱÄã¶ÔÊäÈëµÄÊý¾Ý×÷ÁËaddslashes()´¦Àí£¬
ÄÇôÔÚÊä³öµÄʱºò¾Í±ØÐëʹÓÃstripslashes()È¥µô¶àÓàµÄ·´Ð±¸Ü¡£ 2. ¶ÔÓÚPHP magic_quotes_gpc=off µÄÇé¿ö ±ØÐëÊ¹Ó ......
£¨1£©Ñ¡Ôñ×îÓÐЧÂʵıíÃû˳Ðò£¨Ö»ÔÚ»ùÓÚ¹æÔòµÄÓÅ»¯Æ÷ÖÐÓÐЧ£©
oracleµÄ½âÎöÆ÷°´ÕÕ´ÓÓÒÖÁ×óµÄ˳Ðò´¦Àífrom×Ó¾äÖеıíÃû£¬from×Ó¾äÖÐдÔÚ×îºóµÄ±í£¨»ù´¡±í£©½«×îÏȱ»´¦Àí£¬ÔÚfrom×Ó¾äÖаüº¬¶à¸ö±íµÄÇé¿öÏÂ,Äã±ØÐëÑ¡Ôñ¼Ç¼ÌõÊý×îÉٵıí×÷Ϊ»ù´¡±í¡£Èç¹ûÓÐ3¸öÒÔÉϵıíÁ¬½Ó²éѯ, ÄǾÍÐèҪѡÔñ½»²æ±í(intersection table)×÷Ϊ»ù´ ......
²»ÖªµÀÕâÑùµÄÒªÇóÄܲ»ÄÜʵÏÖ£¿
±ÈÈçÎÒÓÐÒ»ÕűíT1£¬ÀïÃæÖ»ÓÐÒ»¸ö×Ö¶Î1
ÀïÃæÓÐ100Ìõ¼Ç¼£¬ÈçÏÂËùʾ£º
×Ö¶Î1
A1
A2
A3
A4
...
A100
ÎÒÏëÓÃÒ»ÌõSQLÏÔʾÕâÑùµÄ½á¹û
µÚÒ»ÁÐ µÚ¶þÁÐ ... µÚÊ®ÁÐ
A1 A11 &nb ......