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

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
from usertable a,citytable b
WHERE a.cityid=b.cityid
SELEC


Ïà¹ØÎĵµ£º

SQL Server²é詢¿ÉÓôÅÅÌ¿Õ¼ä

--> Title  : SQL Server²é詢¿ÉÓôÅÅÌ¿Õ¼ä
--> Author : wufeng4552
--> Date   : 2009-10-30 09:59:09
Ç°ÑÔ
Èç¹ûÄãµÄ×éÖ¯ÓµÓеijÌÐòÒªÇóÒ»¸öºÜ´óÁ¿µÄ´ÅÅÌ¿Õ¼ä»òÕß´ó±ÈÀýµÄÌض¨´ÅÅÌ£¬ÄÇôȷ±£ÔÚ³ÌÐò¿ªÊ¼»òÕ߹ؼüµãʱȷÈÏ´ÅÅÌÇý¶¯Æ÷¾ßÓÐ×ã¹»µÄ´æ´¢¡£Ò»´Î¿ìËÙ¼ì²é¾Í¿ÉÒÔ½ÚÔ¼´óÁ¿µÄʱ¼ä£¬¼õ ......

SQL Server 2005 EXCEPTºÍINTERSECTÔËËã·û


--> Title  : SQL Server 2005EXCEPTºÍINTERSECTÔËËã·û
--> Author : wufeng4552
--> Date   : 2009-10-30
 
(Ò»)¸ÅÄî
EXCEPTºÍINTERSECTÔËËã·ûʹÄú¿ÉÒԱȽÏÁ½¸ö»ò¶à¸öSELECTÓï¾äµÄ½á¹û²¢·µ»Ø·ÇÖظ´Öµ¡£
(¶þ)區別
EXCEPTÔËËã·û·µ»ØÓÉEXCEPTÔËËã·û×ó²àµÄ²éѯ·µ»Ø¡¢¶øÓÖ² ......

sqlÖ®×óÁ¬½Ó¡¢ÓÒÁ¬½Ó¡¢È«Á¬½Ó

ÎÒÃǽéÉÜÁ˱íÁ¬½Ó£¬¸üÈ·ÇеÄ˵ÊÇinner joins內Á¬½Ó¡£內Á¬½Ó½öÑ¡³öÁ½ÕűíÖл¥ÏàÆ¥ÅäµÄ¼Ç¼£®Òò´Ë£¬Õâ»áµ¼ÖÂÓÐʱÎÒÃÇÐèÒªµÄ¼Ç¼ûÓаüº¬½øÀ´¡£
Ϊ¸üºÃµÄÀí½âÕâ¸ö¸ÅÄÎÒÃǽéÉÜÁ½¸ö±í×÷ÑÝʾ¡£ËÕ¸ñÀ¼Òé»áÖеÄÕþµ³±í(party)ºÍÒéÔ±±í(msp)¡£
 
party(Code,Name,Leader)
Code: Õþµ³´úÂë
Name: Õþµ³Ãû³Æ
Le ......

Oracle SQL*PlusµÄ»·¾³ÅäÖ㨸ü¸ÄÐÐ¿í£©

µ±ÎÒÃÇÓÃoracleµÄSQL*Plus¹¤¾ßÊäÈësqlÓï¾äµÄʱºò£¬SQL*PlusµÄĬÈÏÉèÖÃ×ÜÓÐЩ²»ºÏÀíµÄµØ·½£¬´ËʱÎÒÃÇͨ¹ýÒÔÏÂһЩ·½·¨¸Ä½ø£º
1¡¢¿ÉÒÔÔËÓÃSQL*Plus×ÔÉíһЩÓï¾ä¸Ä±ä»·¾³²ÎÊý¡£
     SQL>  set linesize 900 ;   /* ¸ü¸ÄÏÔʾµÄ¿í¶È, ÉèÖóÉ900ºó, Ò»ÐÐÊý¾Ý¾Í²»»á·ÖÁ½ÐÐÏÔʾÁË */
&nb ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ