ÑÐò½¥½ø½²½âSQL²éѯÓï¾ä¸ß¼¶Ó¦Óü¼ÇÉ
Ò»¡¢ ¼òµ¥²éѯ
¼òµ¥µÄTransact-SQL²éѯֻ°üÀ¨Ñ¡ÔñÁÐ±í¡¢from×Ó¾äºÍWHERE×Ӿ䡣ËüÃÇ·Ö±ð˵Ã÷Ëù²éѯÁС¢²éѯµÄ
±í»òÊÓͼ¡¢ÒÔ¼°ËÑË÷Ìõ¼þµÈ¡£
ÀýÈ磬ÏÂÃæµÄÓï¾ä²éѯtesttable±íÖÐÐÕÃûΪ“ÕÅÈý”µÄnickname×ֶκÍemail×ֶΡ£
SELECT nickname,email
from testtable
WHERE name='ÕÅÈý'
(Ò») Ñ¡ÔñÁбí
Ñ¡ÔñÁбí(select_list)Ö¸³öËù²éѯÁУ¬Ëü¿ÉÒÔÊÇÒ»×éÁÐÃûÁÐ±í¡¢ÐǺš¢±í´ïʽ¡¢±äÁ¿(°üÀ¨¾Ö²¿±ä
Á¿ºÍÈ«¾Ö±äÁ¿)µÈ¹¹³É¡£
1¡¢Ñ¡ÔñËùÓÐÁÐ
ÀýÈ磬ÏÂÃæÓï¾äÏÔʾtesttable±íÖÐËùÓÐÁеÄÊý¾Ý£º
SELECT *
from testtable
2¡¢Ñ¡Ôñ²¿·ÖÁв¢Ö¸¶¨ËüÃǵÄÏÔʾ´ÎÐò
²éѯ½á¹û¼¯ºÏÖÐÊý¾ÝµÄÅÅÁÐ˳ÐòÓëÑ¡ÔñÁбíÖÐËùÖ¸¶¨µÄÁÐÃûÅÅÁÐ˳ÐòÏàͬ¡£
ÀýÈ磺
SELECT nickname,email
from testtable
3¡¢¸ü¸ÄÁбêÌâ
ÔÚÑ¡ÔñÁбíÖУ¬¿ÉÖØÐÂÖ¸¶¨ÁбêÌâ¡£¶¨Òå¸ñʽΪ£º
ÁбêÌâ=ÁÐÃû
ÁÐÃû ÁбêÌâ
Èç¹ûÖ¸¶¨µÄÁбêÌâ²»ÊDZê×¼µÄ±êʶ·û¸ñʽʱ£¬Ó¦Ê¹ÓÃÒýºÅ¶¨½ç·û£¬ÀýÈ磬ÏÂÁÐÓï¾äʹÓúº×ÖÏÔʾÁÐ
±êÌ⣺
SELECT êdzÆ=nickname,µç×ÓÓʼþ=email
from testtable
4.ɾ³ýÖظ´ÐÐ
SELECTÓï¾äÖÐʹÓÃALL»òDISTINCTÑ¡ÏîÀ´ÏÔʾ±íÖзûºÏÌõ¼þµÄËùÓÐÐлòɾ³ýÆäÖÐÖظ´µÄÊý¾ÝÐУ¬Ä¬ÈÏ
ΪALL¡£Ê¹ÓÃDISTINCTÑ¡Ïîʱ£¬¶ÔÓÚËùÓÐÖظ´µÄÊý¾ÝÐÐÔÚSELECT·µ»ØµÄ½á¹û¼¯ºÏÖÐÖ»±£ÁôÒ»ÐС£
5¡¢ÏÞÖÆ·µ»ØµÄÐÐÊý
ʹÓÃTOP n [PERCENT]Ñ¡ÏîÏÞÖÆ·µ»ØµÄÊý¾ÝÐÐÊý£¬TOP n˵Ã÷·µ»ØnÐУ¬¶øTOP n PERCENTʱ£¬ËµÃ÷nÊÇ
±íʾһ°Ù·ÖÊý£¬Ö¸¶¨·µ»ØµÄÐÐÊýµÈÓÚ×ÜÐÐÊýµÄ°Ù·ÖÖ®¼¸¡£
ÀýÈ磺
SELECT TOP 2 *
from testtable
SELECT TOP 20 PERCENT *
from testtable
(¶þ) from×Ó¾ä
from×Ó¾äÖ¸¶¨SELECTÓï¾ä²éѯ¼°Óë²éѯÏà¹ØµÄ±í»òÊÓͼ¡£ÔÚfrom×Ó¾äÖÐ×î¶à¿ÉÖ¸¶¨256¸ö±í»òÊÓͼ£¬
ËüÃÇÖ®¼äÓöººÅ·Ö¸ô¡£
ÔÚfrom×Ó¾äͬʱָ¶¨¶à¸ö±í»òÊÓͼʱ£¬Èç¹ûÑ¡ÔñÁбíÖдæÔÚͬÃûÁУ¬ÕâʱӦʹÓöÔÏóÃûÏÞ¶¨ÕâЩÁÐ
ËùÊôµÄ±í»òÊÓͼ¡£ÀýÈçÔÚusertableºÍcitytable±íÖÐͬʱ´æÔÚcityidÁУ¬ÔÚ²éѯÁ½¸ö±íÖеÄcityidʱӦ
ʹÓÃÏÂÃæÓï¾ä¸ñʽ¼ÓÒÔÏÞ¶¨£º
SELECT username,citytable.cityid
from usertable,citytable
WHERE usertable.cityid=citytable.cityid
ÔÚfrom×Ó¾äÖпÉÓÃÒÔÏÂÁ½ÖÖ¸ñʽΪ±í»òÊÓͼָ¶¨±ðÃû£º
±íÃû as ±ðÃû
±íÃû ±ðÃû
ÀýÈçÉÏÃæÓï¾ä¿ÉÓñíµÄ±ðÃû¸ñʽ±íʾΪ£º
SELECT username,b.cityid
Ïà¹ØÎĵµ£º
±¾ÎĵØÖ·£ºhttp://qzone.qq.com/blog/236000056-1217427602
ÎÞ·¨Á¬½Óµ½·þÎñÆ÷
·þÎñÆ÷£ºÏûÏ¢18452, ¼¶±ð16£¬×´Ì¬1
[Microsoft][ODBC SQLServer Driver][SQL Server]Óû§‘sa’µÇ½ʧ°Ü¡£ÔÒò£ºÎ´ÓëÐÅÈÎSQL ServerÁ¬½ÓÏà¹ØÁª
¸Ã´íÎó²úÉ ......
ʹÓÃ×Ó²éѯµÄÔÔò
1.Ò»¸ö×Ó²éѯ±ØÐë·ÅÔÚÔ²À¨ºÅÖС£
2.½«×Ó²éѯ·ÅÔڱȽÏÌõ¼þµÄÓÒ±ßÒÔÔö¼Ó¿É¶ÁÐÔ¡£
×Ó²éѯ²»°üº¬ ORDER BY ×Ӿ䡣¶ÔÒ»¸ö SELECT Óï¾äÖ»ÄÜÓÃÒ»¸ö ORDER BY ×Ó¾ä,
&nb ......
SQLÊý¾Ý¿âÖÐÓÃimageÀ´´æ´¢Îļþ,µ«SQLûÓÐÌṩֱ½ÓµÄ´æÈ¡ÎļþµÄÃüÁî.
/*--bcp ʵÏÖ¶þ½øÖÆÎļþµÄµ¼Èëµ¼³ö
Ö§³Öimage,text,ntext×ֶεĵ¼Èë/µ¼³ö
imageÊʺÏÓÚ¶þ½øÖÆÎļþ,°üÀ¨:WordÎĵµ,ExcelÎĵµ,ͼƬ,ÒôÀÖµÈ
text,ntextÊʺÏÓÚÎı¾Êý¾ÝÎļþ
×¢Òâ:µ¼Èëʱ,½«¸²¸ÇÂú×ãÌõ¼þµÄËùÓÐÐÐ
µ¼³öʱ,½ ......
sql isnullº¯ÊýµÄʹÓÃ
ISNULL
ʹÓÃÖ¸¶¨µÄÌæ»»ÖµÌæ»» NULL¡£
Óï·¨
ISNULL ( check_expression , replacement_value )
²ÎÊý
check_expression
½«±»¼ì²éÊÇ·ñΪ NULLµÄ±í´ïʽ¡£check_expression ¿ÉÒÔÊÇÈκÎÀàÐ͵ġ£
replacement_value
ÔÚ check_expression Ϊ NULLʱ½«·µ»ØµÄ±í´ïʽ¡£replacement_value ±ØÐëÓë chec ......
1£© Ñ¡Ôñ×îÓÐЧÂʵıíÃû˳Ðò(Ö»ÔÚ»ùÓÚ¹æÔòµÄÓÅ»¯Æ÷ÖÐÓÐЧ)£º
ORACLEµÄ½âÎöÆ÷°´ÕÕ´ÓÓÒµ½×óµÄ˳Ðò´¦Àífrom×Ó¾äÖеıíÃû£¬from×Ó¾äÖÐдÔÚ×îºóµÄ±í(»ù´¡±í driving table)½«±»×îÏÈ´¦Àí£¬ÔÚfrom×Ó¾äÖаüº¬¶à¸ö±íµÄÇé¿öÏÂ,Äã±ØÐëÑ¡Ôñ¼Ç¼ÌõÊý×îÉٵıí×÷Ϊ»ù´¡±í¡£Èç¹ûÓÐ3¸öÒÔÉϵıíÁ¬½Ó²éѯ, ÄǾÍÐèҪѡÔñ½»²æ±í(intersection ......