- ©«¤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(¤T)
not¡G§_©w¥ô¦óÅÞ¿èªí¹F¦¡¡A©Î¬OÃöÁäµü¡A¦plike¡Anull¡Abetweenµ¥¡C
group by©Mhaving¤l¥y¦bselect»y¥y¤¤¨Ï¥Î¡A¥i¥H±Nªí¹º¤À¦¨²Õ¨Ãªð¦^¤Ç°thaving¤l¥y±ø¥óªº²Õ¡C
»yªk¡Gselect»y¥y¶}ÀY
group by [all] aggregate_free_expression [,aggregate_free_expression]*
[having search_conditions]
select»y¥yµ²§À
group by¡G«ü©wªí±N¹º¤Àªº²Õ¸s¡A¦pªG¦bselectªí¶µ¤¤¥]§t¶°¦X¨ç¼Æ¡A«h¬°¦U²Õpºâ¤@ÓÁ`pÈ¡C³o¨ÇÁ`pȪºµ²ªG¥H·sªº¦CÅã¥Ü¡A¦Ó¤£¬O·sªº¦æ¡C¦b having¤l¥y¤¤¨Ï¥ÎªÌ¥i¥H¤Þ¥Î³o¨Ç·sªºÁ`p¦C¡C¦bgroup by¤§«eªºselect_list¤¤¥i¥H¨Ï¥Îavg¡Bcount¡Bmax¡Bmin©Msumµ¥¶°¦X¨ç¼Æ¡Cªí¥i¥H³Q¥ô·N¦Cªº²Õ¦X¤À²Õ¡C
all¡G¦bµ²ªG¤¤¥]§t©Ò¦³²Õ¸sªºTransact-SQLÂX®i¡A³o¸Ìªº©Ò¦³²Õ¸s¬Æ¦Ü¥]¬A¨º¨Ç³Qwhere¤l¥y©Ò±Æ°£ªº²Õ¸s¡C¦pªG¦P®É¨Ï¥Îhaving¤l¥y¡A±N¹ïallªº·N¸q¶i¦æ§_©w¡C
aggregate_free_expression¡G¤£¥]§t¶°¦X¨ç¼Æªºªí¹F¦¡¡ATransact-SQLÂX®i¤¹³\¦b¥Î¦C¦WºÙ¤À²Õªº¦P®É¡A¥ÎµL¶°¦X¨ç¼Æªºªí¹F¦¡¤À²Õ¡C
having¡G¬°group by¤l¥y³]¸m±ø¥ó¡AÃþ¦ü©ówhere¬°select»y¥y³]¸m±ø¥óªº¤èªk¡Chavingªº¬d§ä±ø¥ó¥i¥H¥]¬A¶°¦X¨ç¼Æªí¹F¦¡¡C°£¦¹¤§¥~¡A¥¦ªº¬d§ä±ø¥ó»Pwhere¬d§ä±ø¥ó¬Û¦P¡C
order by¡G«ö¦C±Æ¦Cµ²ªG¡C¹ïselect¿é¥Xªº¦C¥i¥H¥Î¦C¦W¡B¦C§O¦W©Î¦C¦ì¸m¨Ó¤Þ¥Î¡C¨Ò¦p¡Gselect id as myid,name as myname from mytable group by id¡Bselect id as myid,name as myname from mytable group by myid¡Bselect id as myid,name as myname from mytable group by 1³o¤T¥y¬O§¹¥þµ¥»ùªº¡C·íµM¡A§Ṳ́£ÃÙ¦¨¥Î²Ä¤TºØ¥Îªk¡A³o±Nµ¹µ{¦¡ªº¥iŪ©Ê±a¨Ó¤£¦nªº¼vÅT¡C ¬°¤F¥H°§Ç±Æ¦C¡A§âDESCÃöÁäµü¥[¨ìorder by¤l¥y¤¤§An±Æ§Çªº¦C¦W«e¡C¯Ê¬Ù¬O¤É§Ç¡A§A¤]¥i¥H¥ÎASCÃöÁäµü©ú½T«ü©w¡C
limit ¤l¥y¡G¥Î¨Ó¨îselect»y¥yªð¦^ªº¦æ¼Æ¡Climit¨ú1Ó©Î2ӼƦr°Ñ¼Æ¡A¦pªGµ¹©w2ӰѼơA²Ä¤@Ó«ü©wnªð¦^ªº²Ä¤@¦æªº°¾²¾¶q¡A²Ä¤GÓ«ü©wªð¦^¦æªº³Ì¤j¼Æ¥Ø¡Cªì©l¦æªº°¾²¾¶q¬O0¡]¤£¬O1¡^¡C¦pªGµ¹©w¤@ӰѼơA¥¦«ü¥X°¾²¾¶q¬°0ªºªð¦^¦æªº³Ì¤j¼Æ¥Ø¡C¤]´N¬O»¡limit 5©Mlimit 0,5§¹¥þµ¥»ù¡C
¦Ü©óprocedureÃöÁäµüªº§t¸q¡A§Ú¤]¨S·d±o¤Ó²M·¡¡A¦n¹³¬O¹ïÀx¦s¹Lµ{ªº¤ä«ù¡A¦ÓMySQL¥»¨¤£¤ä«ùÀx¦s¹Lµ{¡A¬Ý¨Ó¬O¬°¤F±N¨ÓÂX¥Rªº»Ýn¦Ó«O¯dªº§a |
|