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

sqlÓï¾ä²éѯ½á¹ûºÏ²¢union ºÍunion allÓ÷¨

sqlÓï¾ä²éѯ½á¹ûºÏ²¢union ºÍunion allÓ÷¨
 
--ºÏ²¢Öظ´ÐÐ
select * from A
union
select * from B
--²»ºÏ²¢Öظ´ÐÐ
select * from A
union all
select * from B
°´Ä³¸ö×Ö¶ÎÅÅÐò
--ºÏ²¢Öظ´ÐÐ
select *
from (
select * from A
union
select * from B) AS T
order by ×Ö¶ÎÃû
--²»ºÏ²¢Öظ´ÐÐ
select *
from (
select * from A
union all
select * from B) AS T
order by ×Ö¶ÎÃû
//sql server°æ
Select * from (
select top 2 id,adddate,title,url from bArticle where ClassId='1' order by adddate desc) A
Union All
Select * from (
select top 2 id,adddate,title,url from bArticle where ClassId='2' order by adddate desc) B
Union All
Select * from (
select top 2 id,adddate,title,url from bArticle where ClassId='3' order by adddate desc) C
Union All
Select * from (
select top 2 id,adddate,title,url from bArticle where ClassId='4' order by adddate desc) D
//mysql°æ
Select * from (
select id,adddate,title,url from bArticle where ClassId='1' order by adddate desc limit 0,2) A
Union All
Select * from (
select id,adddate,title,url from bArticle where ClassId='2' order by adddate desc limit 0,2) B
Union All
Select * from (
select id,adddate,title,url from bArticle where ClassId='3' order by adddate desc limit 0,2) C
Union All
Select * from (
select id,adddate,title,url from bArticle where ClassId='4' order by adddate desc limit 0,2) D
ÔÚDB2ÀïʹÓÃunionʱһ¶¨Òª×¢ÒâÏà¶ÔÓ¦µÄ×Ö¶ÎÒ»¶¨ÊÇÊý¾ÝÀàÐÍÒ»Ñù£¬Êä³öʱ¿ÉÒÔÈÎÒâÏÔʾµÄÁУ¬µ«²»ÄÜÊä³ö²»Í¬ÀàÐÍ»ò²»Í¬±í½á¹¹¡£ÒòΪÕâÑù»á³ö´í¡£


Ïà¹ØÎĵµ£º

º½¿Õ¹«Ë¾¹ÜÀíϵͳ(VC++ ÓëSQL 2005)

ϵͳ»·¾³£ºWindows 7
Èí¼þ»·¾³£ºVisual C++ 2008 SP1 +SQL Server 2005
±¾´ÎÄ¿µÄ£º±àдһ¸öº½¿Õ¹ÜÀíϵͳ
      ÕâÊÇÊý¾Ý¿â¿Î³ÌÉè¼ÆµÄ³É¹û£¬ËäÈ»³É¼¨²»¼Ñ£¬µ«ÊÇ×÷ΪÎÒÓÃVC++ ÒÔÀ´±àдµÄ×î´ó³ÌÐò»¹ÊÇ´«µ½ÍøÉÏ£¬ÒÔ¹©²Î¿¼¡£ÓÃVC++ ×öÊý¾Ý¿âÉè¼Æ²¢²»ÈÝÒ×£¬µ«Ò²²»ÊDz»¿ÉÄÜ¡£ÒÔÏÂÊÇÎҵijÌÐò½çÃ棬ºóÃæ ......

SQL Server 2005 Ô¶³ÌÁ¬½Ó

SQL Server 2005 ¿ª·¢°æ²»ÔÊÐíÔ¶³ÌÁ¬½Ó¡£
¡¡¡¡ÒªÔÊÐíÔ¶³ÌÁ¬½ÓSQL Server 2005 ,ÐèÒªÍê³ÉÒÔϲ½Ö裺
•ÔÚSQLServer ʵÀýÉÏÆôÓÃÔ¶³ÌÁ¬½Ó¡£
•´ò¿ª·þÎñÆ÷ SQLBrowser ·þÎñ¡£
•ÅäÖ÷À»ðǽÒÔÔÊÐíSQLBrowser ·þÎñºÍSQLServer·þÎñÍøÂçͨÐÅ¡£
¡¡¡¡ÔÚSQLServer ʵÀýÉÏÆôÓÃÔ¶³ÌÁ¬½Ó
1.Ö¸Ïò“¿ªÊ¼->³ÌÐ ......

SQL ServerÊý¾Ý¿âʱ³öÏÖ¹ÂÁ¢Óû§È¨ÏÞÎÊÌâµÄ½â¾ö°ì

--×Ô¼ººÜÓÞ´ÀµÄ×ö·¨£¬ÒÔΪֱ½Óɾ³ýÊý¾Ý¿âÓû§Ãû£¬ÔÙ´Óд´½¨Óû§µÇ¼ÃûºÍÊý¾Ý¿âÓû§Ãû¡£
--×Ô¼ºÒÔΪ¿ÉÒÔÖ±½Ó´´½¨ÓëÖ®Ô­ÏÈÒ»ÑùµÄÊý¾Ý¿âµÇ¼Ãû¾Í¿ÉÒÔ
--µ«ÕâЩ²Ù×÷ÊDz»Æð×÷ÓõÄ
--Ô­Òò
--µ±Ó³Éä¹ÂÁ¢Óû§Ê±£¬Ö÷´ÓÊý¾Ý¿âÖеÄSID½«·ÖÅä¸ø¹ÂÁ¢Óû§£¬ËùÒÔÿ´ÎÒ»¸öÊý¾Ý¿â±¸¸½¼Ó»òÕß»¹Ô­Ê±£¬--SIDÔÚSQL Server µÇ¼ÃûºÍÊý¾Ý¿âÓû ......

Sql Server ×Ö·û´®¾ÛºÏº¯Êý

 Sql Server ÓÐÈçϼ¸Ö־ۺϺ¯ÊýSUM¡¢AVG¡¢COUNT¡¢COUNT(*)¡¢MAX ºÍ MIN£¬µ«ÊÇÕâЩº¯Êý¶¼Ö»ÄܾۺÏÊýÖµÀàÐÍ£¬ÎÞ·¨¾ÛºÏ×Ö·û´®¡£Èçϱí:AggregationTable
Id Name
1 ÕÔ
2 Ç®
1 Ëï
1 Àî
2 ÖÜ
Èç¹ûÏëµÃµ½ÏÂͼµÄ¾ÛºÏ½á¹û
Id Name
1 ÕÔËïÀî
2 Ç®ÖÜ
ÀûÓÃSUM¡¢AVG¡¢COUNT¡¢COUNT(*)¡¢MAX ºÍ MINÊÇÎÞ·¨×öµ½µ ......

д³ö¸ßÐÔÄÜSQLÓï¾äµÄ35Ìõ·½·¨

£¨1£©ÕûºÏ¼òµ¥,ÎÞ¹ØÁªµÄÊý¾Ý¿â·ÃÎÊ£º
¡¡¡¡Èç¹ûÄãÓм¸¸ö¼òµ¥µÄÊý¾Ý¿â²éѯÓï¾ä,Äã¿ÉÒÔ°ÑËüÃÇÕûºÏµ½Ò»¸ö²éѯÖÐ(¼´Ê¹ËüÃÇÖ®¼äûÓйØϵ)
£¨2£©É¾³ýÖظ´¼Ç¼£º
¡¡¡¡×î¸ßЧµÄɾ³ýÖظ´¼Ç¼·½·¨ ( ÒòΪʹÓÃÁËROWID)Àý×Ó£º
¡¡¡¡DELETE from EMP E WHERE E.ROWID > (SELECT MIN(X.ROWID)
¡¡¡¡from EMP X WHERE X.EMP_NO = E.EM ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ