ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

MySQL¶i¶¥_SELECT½g(¤G)

MySQL¶i¶¥_SELECT½g(¤G)

select list¡G¨ä¤¤¥i¥H¥]§t¤@¶µ©Î¦h¶µ¤U¦C¤º®e¡G
1¡B¡u*¡v¡Aªí¥Ü«ö·Ócreate tableªº¶¶§Ç±Æ¦Cªº©Ò¦³¦C¡C
2¡B«ö·Ó¨Ï¥ÎªÌ©Ò»Ý¶¶§Ç±Æ¦Cªº¦C¦Wªº²M³æ¡C
3¡B¥i¥H¨Ï¥Î§O¦W¨ú¥N¦C¦W¡A§Î¦¡¦p¤U¡Gcolumn name as column_heading¡C
4¡Bªí¹F¦¡¡]¦C¦W¡B±`¶q¡B¨ç¼Æ¡A©Î¥Hºâ³N©Î³v¦ì¹Bºâ²Å³s±µªº¦C¦W¡B±`¶q©M¨ç¼Æªº¥ô¦ó²Õ¦X¡^¡C
5¡B¤º³¡¨ç¼Æ©Î¶°¦X¨ç¼Æ¡C
6¡B¤W­z¦U¶µªº¥ô¦ó¤@ºØ²Õ¦X¡C
FROM¡G¨M©wSELECT©R¥O¤¤¨Ï¥Î­þ¨Çªí¡C¤@¯ë³£­n¨D¦³¦¹¶µ¡A°£«Dselect_list¤¤¤£§t¦C¦W¡]¨Ò¦p¡A¥u¦³±`¶q¡Bºâ³Nªí¹F¦¡µ¥¡^¡C¦pªGªí¶µ¤¤¦³¦h­Óªí¡A¥Î³r¸¹±N¤§¤À¶}¡C¦bÃöÁäµüFROM«á­±ªºªíªº¶¶§Ç¤£¼vÅTµ²ªG¡C
ªí¦W¥i¥Hµ¹¥X¬ÛÃö§O¦W¡A¥H«K¨Ïªí¹F²M´·¡C³o¸Ìªº»yªk¬Otbl_name [AS] alias_name¡C¨Ò¦p¡G
select t1.name,t2.salary from employee as t1,info as t2 where t1.name=t2.name»Pselect t1.name,t2.salary from employee t1,info t2 where t1.name=t2.name¬O§¹¥þµ¥»ùªº¡C
©Ò¦³¹ï¸Óªíªº¨ä¥L¤Þ¥Î¡A¨Ò¦p¦bwhere¤l¥y©Mhaving¤l¥y¤¤¡A³£­n¥Î§O¦W¡A§O¦W¤£¯à¥H¼Æ¦r¶}ÀY¡C
where ¤l¥y³]¸m¤F·j´M±ø¥ó¡A¥¦¦binsert¡Aupdate¡Adelete»y¥y¤¤ªºÀ³¥Î¤èªk¤]»P¦bselect»y¥y¤¤ªºÀ³¥Î¤èªk§¹¥þ¬Û¦P¡C·j´M±ø¥óºò¸ò¦bÃöÁäµü whereªº«á­±¡C¦pªG¨Ï¥ÎªÌ­n¦b»y¥y¤¤¨Ï¥Î¦h­Ó·j´M±ø¥ó¡A«h¥i¥Îand©Îor³s±µ¡C·j´M±ø¥óªº°ò¥»»yªk¬O[not] expression comparison_operator expression¡F[not] expression [not] like ¡umatch_string¡v¡F[not] expression is [not] null¡F[not] expression [not] between expression and expression¡F[not] column_name join_operator column_name¡F[not] boolean_expression¡C
and¡G¥Î¨ÓÁpµ²¨â­Ó±ø¥ó¡A¨Ã¦b¨â­Ó±ø¥ó³£¬OTRUEªº®É­Ôªð¦^µ²ªG¡C·í¦b¦P¤@»y¥y¤¤¨Ï¥Î¦h­ÓÅÞ¿è¹Bºâ²Å®É¡Aand¹Bºâ²ÅÁ`¬O³ÌÀu¥ý¡A°£«D¨Ï¥ÎªÌ¥Î¬A¸¹§ïÅܤF¹Bºâ¶¶§Ç¡C
or¡G¥Î¨ÓÁpµ²¨â­Ó±ø¥ó¡A·í¨â­Ó±ø¥ó¤¤¦³¥ô¤@±ø¥ó¬OTRUEªº®É­Ôªð¦^µ²ªG¡C·í¦b¦P¤@»y¥y¤¤¨Ï¥Î¦h­ÓÅÞ¿è¹Bºâ²Å®É¡A¹Bºâ²Åor³q±`¦b¹Bºâ²Åand¤§«á¶i¦æ¹Bºâ¡C·íµM¨Ï¥ÎªÌ¥i¥H¨Ï¥Î¬A¸¹§ïÅܹBºâªº¶¶§Ç¡C
between¡G¥Î¨Ó¼ÐÃѽd³ò¤U­­ªºÃöÁäµü¡Aand«á­±¸ò½d³ò¤W­­ªº­È¡C½d³òwhere @val between x and y¥]§t­º§À­È¡C¦pªGbetween«á­±«ü©wªº²Ä¤@­Ó­È¤j©ó²Ä¤G­Ó­È¡A«h¸Ó¬d¸ß¤£ªð¦^¥ô¦ó¦æ¡C
column_name¡G¦b¤ñ¸û¤¤¨Ï¥Îªº¦C¦W¡C¦b·|²£¥Íª[¸q®É¡A¤@©w­n«ü©ú¦C©Ò¦bªºªí¦W¡C
comparison_operator¡G¤ñ¸û¹Bºâ²Å¡C¨£¤Uªí¡G
²Å¸¹ ·N¸q
=  µ¥©ó
>  ¤j©ó
<  ¤p©ó
>=  ¤j©óµ¥©ó
<=  ¤p©óµ¥©ó
!=  ¤£µ¥©ó
<>  ¤£µ¥©ó
¦b¤ñ¸ûchar¡Avarchar«¬¸ê®Æ®É¡A¡u<¡vªº·N«ä¬O§ó±µªñ¦r¥ÀªíÀY³¡¡A¡u>¡v¥Nªí§ó±µªñ¦r¥Àªí§À³¡¡C¤@¯ë¨Ó»¡¡A¤p¼g¦r¥À¤j©ó¤j¼g¦r¥À¡A¤j¼g¦r¥À¤j©ó¼Æ¦r¡A¦ý¬O³o¥i¯à¨Ì¿à©óªA°È¾¹¤W¾Þ§@¨t²Îªº¤ñ¸û¶¶§Ç¡C
¦b¤ñ¸û®É¡A¥½§ÀªºªÅ®æ¬O³Q©¿²¤ªº¡C¨Ò¦p¡A¡uDirk¡vµ¥©ó¡uDirk ¡v¡C
¦b¤ñ¸û¤é´Á®É¡A¡u<¡vªí¥Ü¦­©ó¡A¡u>¡vªí¥Ü±ß©ó¡C
¦b¨Ï¥Î¤ñ¸û¹Bºâ²Å¤ñ¸ûcharacter©Mdatetime¸ê®Æ®É¡A»Ý¥Î¤Þ¸¹±N©Ò¦³¸ê®Æ¤Þ°_¨Ó¡C
expression¡G¥i¯à¬O¦C¦W¡B±`¼Æ¡B¨ç¼Æ©ÎªÌ¬O¦C¦W©Î±`¼Æªº¥ô·N²Õ¦X¡A¥H¤Î¥Hºâ³N¹Bºâ²Å©Î³v¦ì¹Bºâ²Å³s±µªº¨ç¼Æ¡Cºâ³N¹Bºâ²Å¦p¤Uªí©Ò¥Ü¡G
²Å¸¹   ·N¸q
+    ¥[¸¹
-    ´î¸¹   
*    ­¼¸¹
/    °£¸¹
is null¡G¦b·j´M¤@­ÓNULL­È®É¨Ï¥Î¡C
like¡GÃöÁäµü¡A¹ïchar¡Bvarchar©Mdatetime¡]¤£¥]¬A¬í©M²@¬í¡^¥i¥H¨Ï¥Îlike¡A¦bMySQL¤¤like¤]¥i¥H¥Î¦b¼Æ¦rªºªí¹F¦¡¤W¡C
·í¨Ï¥ÎªÌ¦b·j´Mdatetime«¬¸ê®Æ®É¡A³Ì¦n¬O¨Ï¥ÎÃöÁäµülike¡A¦]¬°§¹¾ãªºdatetime°O¿ý¥]§t¦UºØ¦U¼Ëªº¤é´Á¤¸¥ó¡C¨Ò¦p¨Ï¥ÎªÌ¦b¦C arrival_time¤¤¥[¤J¤@­Ó­È¡u9:20¡v¡A¦Ó¤l¥ywhere arrival_time=¡u9:20¡v«o¨S¦³µo²{¥¦¡A¦]¬°MySQL§â¿ý¤Jªº¸ê®ÆÂà´«¦¨¤F¡uJan 1,1900 9:20AM¡v¡CµM¦Ó¤l¥ywhere arrival_time like¡u%9:20%¡v´N¯à§ä¨ì¥¦¡C
boolean_expression¡Gªð¦^¡utrue¡v©Î¡ufalse¡v­Èªºªí¹F¦¡¡C
match_string¡G¥Ñ¤å¦r©M³q°t²Å²Õ¦¨ªº¦ê¡A¥Î³æ¤Þ¸¹©ÎÂù¤Þ¸¹¤Þ°_¨Ó¡A¬O¤Ç°t¼Ò¦¡¡C³q°t²Å¦p¤Uªí©Ò¥Ü¡G
²Å¸¹  ·N¸q
%    0©Î¦h­Ó¤å¦rªº¤å¦r¦ê
_    ¥ô¦ó¤@³æ­Ó¤å¦r
­Ó¤Hñ¦W@

        ÀR«ä¦Û¦b : ¦a¤WºØ¤Fµæ¡A´N¤£©öªø¯ó¡F¤ß¤¤¦³µ½¡A´N¤£©ö¥Í´c¡C
ªð¦^¦Cªí ¤W¤@¥DÃD