mysqlÖÐgroupbyÊÇʲôÒâ˼
ÃÕµ×£º group by ÊÇ mysql ÖÐÓÃÓÚ¶ÔÊý¾Ý·Ö×éºÍ¾ÛºÏµÄ sql Óï¾ä¡£ÏêϸÐÎò£º½«¾ßÓÐÏàͬ·Ö×éÒÀ¾ÝÖµµÄ¼Í¼·Ö×éÔÚÒ»Æ𡣶Ôÿ¸ö×éÓ¦ÓþۺϺ¯Êý£¨Èç sum¡¢count¡¢avg£©ÌìÉú»ã×ÜЧ¹û¡£Óŵã°üÀ¨»ã×ÜÊý¾Ý¡¢Ê¶±ðģʽ¡¢Ïû³ýÖظ´¼Í¼ºÍÌá¸ßЧÂÊ¡£·Ö×éÒÀ¾ÝÁбØÐè·ºÆðÔÚ select ×Ó¾äÖУ¬¾ÛºÏº¯ÊýÖ»ÄÜÓ¦ÓÃÓÚÊýÖµ»ò×Ö·ûÀàÐÍÁС£¿ÉÒÔ×éºÏ¶à¸öö¾ÙÐзÖ×飬group by ĬÈÏ°´ÉýÐòÅÅÐò·Ö×éÒÀ¾ÝÁС£
GROUP BY£ºMySQL ÖеķÖ×é²Ù×÷
ʲôÊÇ GROUP BY£¿
GROUP BY ÊÇ MySQL ÖÐÒ»¸öÓÃÓÚ¶ÔÊý¾Ý¾ÙÐзÖ×éºÍ¾ÛºÏµÄ SQL Óï¾ä¡£Ëü½«¾ßÓÐÏàͬ·Ö×éÒÀ¾ÝÖµµÄ¼Í¼·Ö×éÔÚÒ»Æ𣬲¢¶Ôÿ¸ö×éÓ¦ÓþۺϺ¯Êý£¨Èç SUM¡¢COUNT¡¢AVG£©£¬´Ó¶ø±¬·¢»ã×ÜЧ¹û¡£
ÔõÑùʹÓà GROUP BY£¿
GROUP BY Óï¾äµÄÓï·¨ÈçÏ£º
SELECT ¾ÛºÏº¯Êý(ÁÐÃû), ·Ö×éÒÀ¾ÝÁÐ FROM ±íÃû GROUP BY ·Ö×éÒÀ¾ÝÁÐ
µÇ¼ºó¸´ÖÆ
ʾÀý£ºÅÌËã¸÷²¿·ÖµÄ×ÜÈËΪ£º
SELECT SUM(salary), department FROM employees GROUP BY department;
µÇ¼ºó¸´ÖÆ
GROUP BY µÄÓŵã
»ã×ÜÊý¾Ý£¬»ñµÃÕûÌåÇ÷ÊÆ¡£
ʶ±ðÊý¾ÝÖеÄģʽºÍ¹Øϵ¡£
Ïû³ýÖظ´¼Í¼£¬Ìá¸ßÅÌÎÊЧÂÊ¡£
×¢ÖØÊÂÏî
·Ö×éÒÀ¾ÝÁбØÐè·ºÆðÔÚ SELECT ×Ó¾äÖУ¨ÈçÉÏÃæµÄʾÀý£©¡£
¾ÛºÏº¯ÊýÖ»ÄÜÓ¦ÓÃÓÚÊýÖµ»ò×Ö·ûÀàÐÍÁС£
¿ÉÒÔ×éºÏ¶à¸öö¾ÙÐзÖ×飬ʹÓöººÅÍÑÀë¡£
GROUP BY ĬÈÏ°´ÉýÐò¶Ô·Ö×éÒÀ¾Ýö¾ÙÐÐÅÅÐò¡£
ÒÔÉϾÍÊÇmysqlÖÐgroupbyÊÇʲôÒâ˼µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡