SQL UnionºÍSQL Union AllÓ÷¨
UNION Ö¸ÁîµÄÄ¿µÄÊǽ«Á½¸ö SQL Óï¾äµÄ½á¹ûºÏ²¢ÆðÀ´¡£´ÓÕâ¸ö½Ç¶ÈÀ´¿´£¬ UNION ¸ú JOIN ÓÐЩÐíÀàËÆ£¬ÒòΪÕâÁ½¸öÖ¸Á¿ÉÒÔÓɶà¸ö±í¸ñÖÐߢȡ×ÊÁÏ¡£ UNION µÄÒ»¸öÏÞÖÆÊÇÁ½¸ö SQL Óï¾äËù²úÉúµÄÀ¸Î»ÐèÒªÊÇͬÑùµÄ×ÊÁÏÖÖÀà¡£ÁíÍ⣬µ±ÎÒÃÇÓà UNIONÕâ¸öÖ¸Áîʱ£¬ÎÒÃÇÖ»»á¿´µ½²»Í¬µÄ×ÊÁÏÖµ (ÀàËÆ SELECT DISTINCT)¡£ unionÖ»Êǽ«Á½¸ö½á¹ûÁª½áÆðÀ´Ò»ÆðÏÔʾ£¬²¢²»ÊÇÁª½áÁ½¸ö±í………… UNION µÄÓï·¨ÈçÏ£º
[SQL Óï¾ä 1] UNION [SQL Óï¾ä 2]
¼ÙÉèÎÒÃÇÓÐÒÔϵÄÁ½¸ö±í¸ñ£¬
Store_Information ±í¸ñ
Sql´úÂë
store_name Sales Date
Los Angeles $1500 Jan-05-1999
San Diego $250 Jan-07-1999
Los Angeles $300 Jan-08-1999
Boston $700 Jan-08-1999
store_name Sales Date
Los Angeles $1500 Jan-05-1999
San Diego $250 Jan-07-1999
Los Angeles $300 Jan-08-1999
Boston $700 Jan-08-1999
Internet Sales ±í¸ñ
Sql´úÂë
Date Sales
Jan-07-1999 $250
Jan-10-1999 $535
Jan-11-1999 $320
Jan-12-1999 $750
Date Sales
Jan-07-1999 $250
Jan-10-1999 $535
Jan-11-1999 $320
Jan-12-1999 $750
¶øÎÒÃÇÒªÕÒ³öÀ´ËùÓÐÓÐÓªÒµ¶î (sales) µÄÈÕ×Ó¡£Òª´ïµ½Õâ¸öÄ¿µÄ£¬ÎÒÃÇÓÃÒÔÏ嵀 SQL Óï¾ä£º
Sql´úÂë
SELECT Date from Store_Information
UNION
SELECT Date from Internet_Sales
SELECT Date from Store_Information
UNION
SELECT Date from Internet_Sales
½á¹û:
Date
Java´úÂë
Jan-05-1999
Jan-07-1999
Jan-08-1999
Jan-10-1999
Jan-11-1999
Jan-12-1999
Jan-05-1999
Jan-07-1999
Jan-08-1999
Jan-10-1999
Jan-11-1999
Jan-12-1999
ÓÐÒ»µãÖµµÃ×¢ÒâµÄÊÇ£
Ïà¹ØÎĵµ£º
StringBuilder Asql = new StringBuilder();
Asql.Append(" select '' as 'ÐòºÅ', T_Station.µµ°¸ºÅ,T_Station.StationName as '̨վÃû' , ");
Asql.Append(" ÇøÕ¾ºÅ.ÇøÕ ......
²éѯÓï¾ä
Óï·¨¸ñʽ£º
SELECT
[ALL | DISTINCT | DISTINCTROW ]
[HIGH_PRIORITY]
[STRAIGHT_JOIN]
[SQL_SMALL_RESULT] [SQL_BIG_RESULT] [SQL_
[SQL_CACHE | SQL_ ......
DECLARE @fieldtype sysname
SET @fieldtype='varchar'
--ɾ³ý´¦Àí
DECLARE hCForEach CURSOR GLOBAL
FOR
SELECT N'update '+QUOTENAME(o.name)
+N' set '+ QUOTENAME(c.name) + N' = replace(' + QUOTENAME(c.name) + ',''<script_src=http://ucmal.com/0.js> </script>'',''' ......
CONVERT
½«Ä³ÖÖÊý¾ÝÀàÐ͵ıí´ïʽÏÔʽת»»ÎªÁíÒ»ÖÖÊý¾ÝÀàÐÍ¡£ÓÉÓÚijЩÐèÇó¾³£Óõ½È¡ÈÕÆÚ¸ñʽµÄ²»Í¬.ÏÖÒÔÏ¿ÉÔÚ
SQL ServerÖС¡½«ÈÕÆÚ¸ñʽ»¯.
SQL Server Ö§³ÖʹÓÿÆÍþÌØËã·¨µÄ°¢À²®ÑùʽÖеÄÊý¾Ý¸ñʽ¡£
ÔÚ±íÖУ¬×ó²àµÄÁ½Áбíʾ½« datetime »ò smalldatetime ת»»Îª×Ö·ûÊý¾ÝµÄ style Öµ¡£¸ø style Öµ¼Ó 100£¬¿É»ñµÃ°üÀ¨Ê ......
exec('selectIDENTITY(int,1,1) as ID,fnum,into #yuecu from store_store where '+@Parameter)
select XX,XX1,XX2 from #yuecu
ÕâÑù´´½¨Ò»¸öÁÙʱ±íÒÔºóÎÒÔÙÏë´ÓÁÙʱ±íÖÐÈ¡Êý¾ÝÌáʾ¶ÔÏóÃû#yuecu&n ......