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

SQL ͨÅä·û

SQL ͨÅä·û
 
ÔÚËÑË÷Êý¾Ý¿âÖеÄÊý¾Ýʱ£¬Äú¿ÉÒÔʹÓà SQL ͨÅä·û¡£
SQL ͨÅä·û
ÔÚËÑË÷Êý¾Ý¿âÖеÄÊý¾Ýʱ£¬SQL ͨÅä·û¿ÉÒÔÌæ´úÒ»¸ö»ò¶à¸ö×Ö·û¡£
SQL ͨÅä·û±ØÐëÓë LIKE ÔËËã·ûÒ»ÆðʹÓá£
ÔÚ SQL ÖУ¬¿ÉʹÓÃÒÔÏÂͨÅä·û£º
ͨÅä·ûÃèÊö
%
Ìæ´úÒ»¸ö»ò¶à¸ö×Ö·û
_
½öÌæ´úÒ»¸ö×Ö·û
[charlist]
×Ö·ûÁÐÖеÄÈκε¥Ò»×Ö·û
[^charlist]
»òÕß
[!charlist]
²»ÔÚ×Ö·ûÁÐÖеÄÈκε¥Ò»×Ö·û
ԭʼµÄ±í (ÓÃÔÚÀý×ÓÖеÄ)£º
Persons ±í:
IdLastNameFirstNameAddressCity
1
Adams
John
Oxford Street
London
2
Bush
George
Fifth Avenue
New York
3
Carter
Thomas
Changan Street
Beijing
ʹÓà % ͨÅä·û
Àý×Ó 1
ÏÖÔÚ£¬ÎÒÃÇÏ£Íû´ÓÉÏÃæµÄ "Persons" ±íÖÐÑ¡È¡¾ÓסÔÚÒÔ "Ne" ¿ªÊ¼µÄ³ÇÊÐÀïµÄÈË£º
ÎÒÃÇ¿ÉÒÔʹÓÃÏÂÃæµÄ SELECT Óï¾ä£º
SELECT * from Persons
WHERE City LIKE 'Ne%'
½á¹û¼¯£º
IdLastNameFirstNameAddressCity
2
Bush
George
Fifth Avenue
New York
Àý×Ó 2
½ÓÏÂÀ´£¬ÎÒÃÇÏ£Íû´Ó "Persons" ±íÖÐÑ¡È¡¾ÓסÔÚ°üº¬ "lond" µÄ³ÇÊÐÀïµÄÈË£º
ÎÒÃÇ¿ÉÒÔʹÓÃÏÂÃæµÄ SELECT Óï¾ä£º
SELECT * from Persons
WHERE City LIKE '%lond%'
½á¹û¼¯£º
IdLastNameFirstNameAddressCity
1
Adams
John
Oxford Street
London
ʹÓà _ ͨÅä·û
Àý×Ó 1
ÏÖÔÚ£¬ÎÒÃÇÏ£Íû´ÓÉÏÃæµÄ "Persons" ±íÖÐÑ¡È¡Ãû×ֵĵÚÒ»¸ö×Ö·ûÖ®ºóÊÇ "eorge" µÄÈË£º
ÎÒÃÇ¿ÉÒÔʹÓÃÏÂÃæµÄ SELECT Óï¾ä£º
SELECT * from Persons
WHERE FirstName LIKE '_eorge'
½á¹û¼¯£º
IdLastNameFirstNameAddressCity
2
Bush
George
Fifth Avenue
New York
Àý×Ó 2
½ÓÏÂÀ´£¬ÎÒÃÇÏ£Íû´Ó "Persons" ±íÖÐÑ¡È¡µÄÕâÌõ¼Ç¼µÄÐÕÊÏÒÔ "C" ¿ªÍ·£¬È»ºóÊÇÒ»¸öÈÎÒâ×Ö·û£¬È»ºóÊÇ "r"£¬È»ºóÊÇÈÎÒâ×Ö·û£¬È»ºóÊÇ "er"£º
ÎÒÃÇ¿ÉÒÔʹÓÃÏÂÃæµÄ SELECT Óï¾ä£º
SELECT * from Persons
WHERE LastName LIKE 'C_r_er'
½á¹û¼¯£º
IdLastNameFirstNameAddressCity
3
Carter
Thomas
Changan Street
Beijing
ʹÓà [charlist] ͨÅä·û
Àý×Ó 1
ÏÖÔÚ£¬ÎÒÃÇÏ£Íû´ÓÉÏÃæµÄ "Persons" ±íÖÐÑ¡È¡¾ÓסµÄ³ÇÊÐÒÔ "A" »ò "L" »ò "N" ¿ªÍ·µÄÈË£º
ÎÒÃÇ¿ÉÒÔʹÓÃÏÂÃæµÄ SELECT Óï¾ä£º
SELECT * from Persons
WHERE City LIKE '[ALN]%'
½á¹û¼¯£º
IdLastNameFirstNameAddressCity
1
Adams
John
Oxford Street
London
2
Bush
George
Fifth Avenue
New York
Àý×Ó 2
ÏÖÔÚ£¬ÎÒÃÇÏ£Íû´ÓÉÏÃæµÄ "P


Ïà¹ØÎĵµ£º

ÈÃÈË·¢¿ñµÄsqlÓï¾ä£¡

StringBuilder Asql = new StringBuilder();
            Asql.Append(" select '' as 'ÐòºÅ', T_Station.µµ°¸ºÅ,T_Station.StationName as '̨վÃû' , ");
            Asql.Append("  ÇøÕ¾ºÅ.ÇøÕ ......

SQLÓïÑÔ»ù´¡£¨4£©

UNION½«Á½¸ö»òÁ½¸öÒÔÉϵIJéѯ½á¹ûºÏ²¢ÎªÒ»¸ö½á¹û¼¯£¬ËüÓëʹÓÃÁ¬½Ó²éѯºÏ²¢Á½¸ö±íµÄÁÐÊDz»Í¬µÄ£¬Ê¹
ÓÃUNIONºÏ²¢²éѯ±ØÐë×ñÊØ£º1ÁеÄÊýÄ¿ºÍ˳Ðò±ØÐëÒ»Ö£»2Êý¾ÝµÄÀàÐͱØÐë¼æÈÝ¡£
select Óï¾ä
UNION [all]
select Óï¾ä
¿ÉÒÔ¿´µ½£¬Ö»Òª¶ÔÓ¦×ֶεÄÀàÐÍÏàͬ¾Í¿ÉÒÔÍê³ÉºÏ²¢²Ù×÷£¬µ«ÊÇΪÁËÓÐÒâÒ壬Á½¸ö²éѯµÄ½á¹ûÓ¦¸ÃΪÏàͬ
µ ......

SQL SERVER 2005 »ñÈ¡±í½á¹¹ÐÅÏ¢

SELECT ±íÃû   = CASE a.colorder WHEN 1 THEN c.name ELSE '' END,
       Ðò     = a.colorder,
       ×Ö¶ÎÃû = a.name,
       ±êʶ   = CASE COLUMNPROPERTY(a.id,a.name, ......

SQL UnionºÍSQL Union AllÓ÷¨

UNION Ö¸ÁîµÄÄ¿µÄÊǽ«Á½¸ö SQL Óï¾äµÄ½á¹ûºÏ²¢ÆðÀ´¡£´ÓÕâ¸ö½Ç¶ÈÀ´¿´£¬ UNION ¸ú JOIN ÓÐЩÐíÀàËÆ£¬ÒòΪÕâÁ½¸öÖ¸Á¿ÉÒÔÓɶà¸ö±í¸ñÖÐߢȡ×ÊÁÏ¡£ UNION µÄÒ»¸öÏÞÖÆÊÇÁ½¸ö SQL Óï¾äËù²úÉúµÄÀ¸Î»ÐèÒªÊÇͬÑùµÄ×ÊÁÏÖÖÀà¡£ÁíÍ⣬µ±ÎÒÃÇÓà UNIONÕâ¸öÖ¸Áîʱ£¬ÎÒÃÇÖ»»á¿´µ½²»Í¬µÄ×ÊÁÏÖµ (ÀàËÆ SELECT DISTINCT)¡£ unionÖ»Êǽ«Á½¸ö½á¹ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ