- ©«¤l
- 20
- ¥DÃD
- 18
- ºëµØ
- 0
- ¿n¤À
- 43
- ÂI¦W
- 0
- §@·~¨t²Î
- windows xp
- ³nÅ骩¥»
- Office 2003
- ¾\ŪÅv
- 10
- ©Ê§O
- ¨k
- µù¥U®É¶¡
- 2011-9-5
- ³Ì«áµn¿ý
- 2011-9-6
|
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¤Wz¦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¤@©wn«ü©ú¦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 |
|