ʹÓÃ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;
 
Ïà¹ØÎĵµ£º
½ñÌìÖÕÓÚÖªµÀSQL 2005 ÔõôÓÃÁË£¬¸Ð¾õÒÔǰ̫ÀÁÁË£¬Ã÷Ã÷ÏëÖªµÀµÄ¶«Î÷¿ÉÊÇÒòΪÒѾÓÐsql2000¾ÍÀÁµÃ²é¡£ÖªÊ¶Õâ¶«Î÷ÊÇÈÕ»ýÔÂÀ۵ģ¬ÕæÕýµ½ÓõÄʱºò²ÅÈ¥²¹¾ÍÒѾÍíÁË¡£
ÒÔǰ°²×°VS2005µÄʱºò¾Í¿´µ½°²×°ÍêÁËÒÔºó»áÓÐÒ»¸öSQL2005£¬¿ÉÊÇ×Ô¼º²»»áÓã¬ÄǸöʱºòÖ» ......
ÔÚVSÖÐдSQLÓï¾äµÄʱºò£¬Ç§ÍòÍòǧҪСÐÄÔÙСÐÄ£¬±ÈÈç ˵ Êý¾ÝÀàÐÍµÄÆ¥Å䣬 µ¥ÒýºÅ£¨Õâ¸öÄܰÑÈËÃÔËÀ£©
where ×Ó¾äÖпÉǧÍò²»ÄÜÓпոñ£¨µ±²éѯÌõ¼þΪ×Ö·û´®µÄʱºòÄܰÑÄãŪ·è£¬ÎÒŪÕâ¸öµÄʱºò¶¼·èÁ˼¸´ÎÁË£¬Ê²Ã´¶¼¶Ô¾ÍÊDz鲻³öÀ´£¬µ÷ÊÔÁËN±é²Å·¢ÏÖ¡££©²»ÐÐÁË£¬³Ô·¹È¥£¬ÔÙ²»³Ô¿´¼û»îÈ˶¼ÏëÒ§ÁË¡£ ......
£¨1£©Ñ¡Ôñ×îÓÐЧÂʵıíÃû˳Ðò£¨Ö»ÔÚ»ùÓÚ¹æÔòµÄÓÅ»¯Æ÷ÖÐÓÐЧ£©
oracleµÄ½âÎöÆ÷°´ÕÕ´ÓÓÒÖÁ×óµÄ˳Ðò´¦Àífrom×Ó¾äÖеıíÃû£¬from×Ó¾äÖÐдÔÚ×îºóµÄ±í£¨»ù´¡±í£©½«×îÏȱ»´¦Àí£¬ÔÚfrom×Ó¾äÖаüº¬¶à¸ö±íµÄÇé¿öÏÂ,Äã±ØÐëÑ¡Ôñ¼Ç¼ÌõÊý×îÉٵıí×÷Ϊ»ù´¡±í¡£Èç¹ûÓÐ3¸öÒÔÉϵıíÁ¬½Ó²éѯ, ÄǾÍÐèҪѡÔñ½»²æ±í(intersection table)×÷Ϊ»ù´ ......
Èç¹ûÔÀ´µÄÊý¾Ý¿â¿ÉÓ㬷ÖÀëÊý¾Ý¿âºó£¬Ö»¸½¼ÓÊý¾ÝÎļþ£¬²»¸½¼ÓÈÕÖ¾
Èç¹û²»¿ÉÓã¬Ö»ÄÜÂýÂýµÈ»¹Ô²Ù×÷Íê³ÉÁË
ÈÕÖ¾ÎļþÌ«´óÁË£¬Ó¦¸Ã¶¨ÆÚÕûÀíÈÕÖ¾
--ѹËõÈÕÖ¾¼°Êý¾Ý¿âÎļþ´óС
&n ......
SQL SERVER 2005 ÖеÄÈÕÆÚʱ¼äÀàÐÍ
Ò»£® Êý¾ÝÀàÐÍ
MS SQL Server 2005 ÓÐ datetime ºÍ smalldatetime Á½ÖÖ¸ñʽµÄÈÕÆÚʱ¼äÊý¾ÝÀàÐÍ¡£×¢Ò⣺ûÓе¥¶ÀµÄÈÕÆÚ»òʱ¼äÀàÐÍ¡£
datetime
Êý¾Ý¿âÄÚ²¿ÓÃÁ½¸ö 4 ×Ö½ÚµÄÕûÊý´æ´¢ datetime Êý¾ÝÀàÐ͵ÄÖµ¡£µÚÒ»¸ö 4 ×Ö½Ú´æ´¢»ù´¡ÈÕÆÚ£¨¼´ 1900-1-1, base ......