Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

SQLÖÐÖ÷¼üºÍÍâ¼üµÄÇø±ð

Ö÷¼ü:
Äܹ»Î¨Ò»±íʾÊý¾Ý±íÖеÄÿ¸ö¼Ç¼µÄ¡¾×ֶΡ¿»òÕß¡¾×ֶΡ¿µÄ×éºÏ¾Í³ÆΪÖ÷Âë(Ö÷¼ü)¡£ Ò»¸öÖ÷¼üÊÇΨһʶ±ðÒ»¸ö±íµÄÿһ¼Ç¼£¬µ«ÕâÖ»ÊÇÆä×÷ÓõÄÒ»²¿·Ö£¬Ö÷¼üµÄÖ÷Òª×÷ÓÃÊǽ«¼Ç¼ºÍ´æ·ÅÔÚÆäËû±íÖеÄÊý¾Ý½øÐйØÁª¡£ÔÚÕâÒ»µãÉÏ£¬Ö÷¼üÊDz»Í¬±íÖи÷¼Ç¼֮¼äµÄ¼òµ¥Ö¸Õë¡£Ö÷¼üÔ¼Êø¾ÍÊÇÈ·¶¨±íÖеÄÿһÌõ¼Ç¼¡£Ö÷¼ü²»ÄÜÊÇ¿ÕÖµ¡£Î¨Ò»Ô¼ÊøÊÇÓÃÓÚÖ¸¶¨Ò»¸ö»ò¶à¸öÁеÄ×éºÏÖµ¾ßÓÐΩһÐÔ£¬ÒÔ·ÀÖ¹ÔÚÁÐÖÐÊäÈëÖظ´µÄÖµ¡£ËùÒÔ£¬Ö÷¼üµÄÖµ¶ÔÓû§¶øÑÔÊÇûÓÐʲôÒâÒ壬²¢ÇÒºÍËüÒª¸³ÓèµÄֵҲûÓÐʲôÌرðµÄÁªÏµ¡£
Íâ¼ü£º
ÈôÓÐÁ½¸ö±íA£¬B£¬CÊÇAµÄÖ÷¼ü£¬¶øBÖÐÒ²ÓÐC×ֶΣ¬ÔòC¾ÍÊDZíBµÄÍâ¼ü¡£Íâ¼üÔ¼ÊøÖ÷ÒªÓÃÀ´Î¬»¤Á½¸ö±íÖ®¼äÊý¾ÝµÄÒ»ÖÂÐÔ¡£
AΪ»ù±¾±í£¬BΪÐÅÏ¢±í


Ïà¹ØÎĵµ£º

ÈÃUNIONÓëORDER BY²¢´æÓÚSQLÓï¾äµ±ÖÐ

http://www.cnblogs.com/yinzhenzhixin/archive/2009/01/07/1371064.html
ÔÚSQLÓï¾äÖУ¬UNION¹Ø¼ü×Ö¶àÓÃÀ´½«²¢ÁеĶà×é²éѯ½á¹û(±í)ºÏ²¢³ÉÒ»¸ö½á¹û(±í)£¬¼òµ¥ÊµÀýÈçÏ£º
SELECT [Id],[Name],[Comment] from [Product1]
UNION
SELECT [Id],[Name],[Comment] from [Product2]
ÉÏÃæµÄ´úÂë¿ ......

½«SQL ServerÊý¾Ý¿âÖмǼµ¼³öΪinsertÓï¾ä

   ÓÐʱÔÚ×ö³ÌÐòʱ£¬²âÊÔʱµÄÊý¾Ý£¬ÒªÄÃÏñÓû§ÑÝʾ£¬Êý¾Ý¿âµÄ¸½¼ÓÊÇ×îÖ±½ÓµÄ°ì·¨£¬µ«Èô´ÓSQL Server 2005תÏò2000µ¼³öÂé·³£¬ÄÚÈÝÒ²¶à£¬Éú³ÉSQLÓï¾äÊÇ×îºÃµÄ°ì·¨£¬Ò²ÊÇÔÚÍøÉÏÕҵŤ¾ß,mssql2µ¼³ö·Ç³£·½±ã£¬µ£ÐÄÎÒÒÔºóÄѵÃÕÒËùÒÔ·ÅÔÚÕâÀÒÔ±¸ºóÓᣠ......

SQL³£Ó÷ÖÒ³µÄ°ì·¨ תÔØ

±íÖÐÖ÷¼ü±ØÐëΪ±êʶÁУ¬[ID] int IDENTITY (1,1)
1.·ÖÒ³·½°¸Ò»£º(ÀûÓÃNot InºÍSELECT TOP·ÖÒ³)
Óï¾äÐÎʽ£º
SELECT TOP Ò³¼Ç¼ÊýÁ¿ *
from ±íÃû
WHERE (ID NOT IN
(SELECT TOP (ÿҳÐÐÊý*(Ò³Êý-1)) ID
from ±íÃû
ORDER BY ID))
ORDER BY ID
//×Ô¼º»¹¿ÉÒÔ¼ÓÉÏһЩ²éѯÌõ¼þ
Àý:
select top 2 ......

Sql Server µÄÐÔÄܲâÊÔÊý¾ÝµÄÏÝÚå

Êý¾Ý¿âµÄÐÔÄܲâÊÔ¿ÉÒÔ°ïÖúÄãÌáÇ°ÖªµÀÄãµÄϵͳµÄ¸ºÔØÄÜÁ¦£¬¿ÉÒÔ°ïÖúÄã¸Ä½øϵͳµÄʵʩ»òÉè¼Æ£¬¿ÉÒÔ°ïÖúÄãÈ·¶¨Ò»Ð©Éè¼ÆºÍ±à³ÌÔ­Ôò. µ«ÊÇ£¬ÕâÀïÃæÒ²ÓÐÏÝÚå. Èç¹û²»Ð¡ÐÄ£¬Äã»á×Ô¼º°Ñ×Ô¼ºÏݽøÈ¥£¬È´×îÖÕ²»Ã÷°×ÊÇʲôԭÒò. ÕâÀÎÒÄÃһλÏÈÉúΪÀý£¬À´¿´¿´ËûÔõô×Ô¼º°Ñ×Ô¼º¸ãºýÍ¿µÄ.
×î½ü, ÏëÆðÔÚ´æ´¢¹ý³ÌÖо¿¾¹ÊÇʹÓÃÁÙʱ±í»¹ÊÇÊ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ