group byÔÚsqlÖÐʲôÒâ˼
group by ×Ӿ佫Êý¾Ý¼¯»®·ÖΪ×飬ÒÀ¾ÝÊÇÖ¸¶¨Áлò±í´ïʽ£¬½«Ïàͬ·Ö×éÒÀ¾ÝÖµµÄ¼Í¼¹éΪһ×é¡£Ëü¿ÉÓÃÓÚ»ã×ÜÅÌËã»ò¾ÛºÏÊý¾Ý£¬ÈçÅÌËãÿ¸ö²úÆ·ÀàÐ͵ÄÏúÊÛ×ܶƽ¾ùÖµºÍ×î´óÖµ¡£
GROUP BY ×Ó¾äÔÚ SQL ÖеļÄÒå
GROUP BY ×Ó¾äÊÇ SQL ÖÐÒ»ÏîÇ¿Ê¢µÄ¹¤¾ß£¬ÓÃÓÚ½«Êý¾Ý¼¯Öеļͼ·Ö×飬ÒÔ±ã¶Ô·Ö×é¾ÙÐлã×ÜÅÌËã»ò¾ÛºÏ¡£
ÔË×÷·½·¨£º
GROUP BY ×Ӿ佫Êý¾Ý¼¯Öеļͼ·Ö×飬Æä·Ö×éÒÀ¾ÝÊÇÖ¸¶¨µÄÁлò±í´ïʽ¡£·Ö×éʱ£¬¾ßÓÐÏàͬ·Ö×éÒÀ¾ÝÖµµÄ¼Í¼½«±»¹éΪһ×é¡£
Óï·¨£º
SELECT ÁÐÃû, ¾ÛºÏº¯Êý(ÁÐÃû) FROM ±íÃû WHERE Ìõ¼þ GROUP BY ·Ö×éÒÀ¾Ý
µÇ¼ºó¸´ÖÆ
ʾÀý£º
ÒÔÏÂÅÌÎʽ«±í “Sales” ÖеÄÏúÊÛÊý¾Ý°´²úÆ·ÀàÐÍ·Ö×飬²¢»ã×ÜÿÖÖÀàÐͲúÆ·µÄÏúÊÛ×ܶ
SELECT ProductType, SUM(SalesAmount) FROM Sales GROUP BY ProductType
µÇ¼ºó¸´ÖÆ
Ч¹û£º
¸ÃÅÌÎʽ«·µ»ØÒ»¸öЧ¹û¼¯£¬ÆäÖÐÿÐдú±íÒ»ÖÖ²úÆ·ÀàÐÍ£¬ÒÔ¼°¸ÃÀàÐͲúÆ·µÄÏúÊÛ×ܶ
ÆäËûÓ÷¨£º
GROUP BY ×Ó¾äÒ²¿ÉÒÔÓÃÓÚÖ´ÐÐÒÔϲÙ×÷£º
ÅÌËãƽ¾ùÖµ¡¢×î´óÖµºÍ×îСֵµÈ¾ÛºÏº¯Êý¡£
¼ÆÊýÖظ´Ïî¡£
ɾ³ýÖظ´ÐС£
ÒÔÉϾÍÊÇgroup byÔÚsqlÖÐʲôÒâ˼µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡