尊龙凯时人生就是博

mysqlÖÐgroupbyÔõôÓÃË÷Òý

ÔÚ mysql ÖÐʹÓà group by ʱ£¬Ë÷ÒýµÄʹÓÿÉÒÔ¼«´óµØÌá¸ßÐÔÄÜ£¬Ìõ¼þÊÇ£ºÈ·±£Ë÷ÒýÁÐÓë group by ×Ó¾äÖеÄÁÐÆ¥Åä¡£½¨É踴ºÏË÷ÒýÒÔÌá¸ß·Ö×éÉæ¼°¶à¸öÁÐʱµÄÐÔÄÜ¡£Ê¹ÓÃÁýÕÖË÷ÒýÒÔ×èÖ¹»á¼û±í²¢Ö±½Ó´ÓË÷ÒýÖмìË÷Êý¾Ý¡£×èֹʹÓà order by ×Ó¾äÖв»ÔÚ group by ×Ó¾äÖеÄÁС£

MySQL ÖÐʹÓà GROUP BY ʱË÷ÒýµÄʹÓÃ

ÔÚ MySQL ÖУ¬GROUP BY ÊÇÒ»Ö־ۺϺ¯Êý£¬ÓÃÓÚ¶ÔÊý¾Ý¼¯¾ÙÐзÖ×é²¢ÅÌËãÿ¸ö×éµÄ»ã×ÜÖµ¡£Ë÷Òý¿ÉÒÔ¼«´óµØÌá¸ß GROUP BY ÅÌÎʵÄÐÔÄÜ£¬Ìõ¼þÊÇË÷ÒýÁÐÓë GROUP BY ×Ó¾äÖеÄÁÐÆ¥Åä¡£

µ±ÔÚ GROUP BY ÅÌÎÊÖÐʹÓÃË÷Òýʱ£¬Ë÷Òý¿ÉÒÔÓÃÀ´¿ìËÙ¶¨Î»Òª¾ÛºÏµÄÐеÄÜöÝÍ¡£Õâ¿ÉÒÔ×èÖ¹¶ÔÕû¸ö±í¾ÙÐÐÈ«±íɨÃ裬´Ó¶øÏÔ×ÅÌá¸ßÅÌÎÊÐÔÄÜ¡£

ÒÔÏÂÊÇÔõÑùÔÚ MySQL GROUP BY ÅÌÎÊÖÐʹÓÃË÷Òý£º

È·±£Ë÷ÒýÁÐÓë GROUP BY ×Ó¾äÖеÄÁÐÆ¥Å䣺½¨ÉèË÷Òýʱ£¬Ó¦È·±£Ë÷ÒýÁÐÓë GROUP BY ×Ó¾äÖÐʹÓõÄÁÐÍêÈ«Æ¥Åä¡£²»È»£¬Ë÷Òý½«ÎÞ·¨ÓÃÓÚÓÅ»¯ÅÌÎÊ¡£

½¨É踴ºÏË÷Òý£ºÈôÊÇ GROUP BY ÅÌÎÊÉæ¼°¶à¸öÁУ¬Ôò½¨É踴ºÏË÷Òý¿ÉÒÔ½øÒ»²½Ìá¸ßÐÔÄÜ¡£¸´ºÏË÷Òý°üÀ¨¶à¸öÁУ¬²¢ÇÒµ±Ê¹ÓÃÕâЩö¾ÙÐзÖ×éʱ£¬¿ÉÒÔÓÐÓõؼÓËÙ²éÕÒËÙÂÊ¡£

ʹÓÃÁýÕÖË÷Òý£ºÁýÕÖË÷Òý°üÀ¨ÅÌÎÊÖÐËùÓÐÐëÒªµÄÁУ¬ÕâʹµÃ MySQL ¿ÉÒÔÔÚ²»»á¼û±íµÄÇéÐÎÏ´ÓË÷ÒýÖÐÖ±½Ó¼ìË÷ËùÓбØÐèµÄÊý¾Ý¡£¹ØÓÚ GROUP BY ÅÌÎÊ£¬Õâ¿ÉÒÔÏÔÖøÌá¸ßÐÔÄÜ¡£

×èֹʹÓà ORDER BY£ºÈôÊÇ ORDER BY ×Ó¾ä°üÀ¨²»ÔÚ GROUP BY ×Ó¾äÖеÄÁУ¬Ôò MySQL ½«ÎÞ·¨Ê¹ÓÃË÷Òý¾ÙÐзÖ×é²Ù×÷¡£

ʾÀý£º

˼Á¿ÒÔÏÂÅÌÎÊ£º

SELECT department, SUM(salary)
FROM employees
GROUP BY department;

µÇ¼ºó¸´ÖÆ

ÈôÊÇÔÚ department ÁÐÉϱ£´æË÷Òý£¬Ôò MySQL ¿ÉÒÔʹÓôËË÷ÒýÀ´¿ìËÙ²éÕÒÿ¸ö²¿·ÖµÄ¼Í¼¡£Õ⽫×èÖ¹¶ÔÕû¸ö employees ±í¾ÙÐÐÈ«±íɨÃ裬´Ó¶øÏÔ×ÅÌá¸ßÅÌÎÊÐÔÄÜ¡£

ÒÔÉϾÍÊÇmysqlÖÐgroupbyÔõôÓÃË÷ÒýµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是博ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是博ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是博

13452372176

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ