groupbyÊÇʲôÒâ˼ÔÚsqlÖÐ
group by ÊÇ sql ÖÐÓÃÓÚ·Ö×éºÍ¾ÛºÏÊý¾ÝµÄÓï¾ä¡£Ëü°´·Ö×é¼ü½«ÐзÖ×飬ȻºóÓ¦ÓþۺϺ¯Êý£¬ÀýÈçÅÌËã×ܺ͡¢¼ÆÊý»òƽ¾ùÖµ¡£
GROUP BY ÔÚ SQL ÖеļÄÒå
GROUP BY ÊÇ SQL ÖеÄÒ»ÌõÓï¾ä£¬ÓÃÓÚ½«Êý¾Ý¼¯ÖеÄÐзÖ×é²¢¾ÛºÏÏàͬ×éÖеÄÊý¾Ý¡£
ÊÂÇéÔÀí
GROUP BY Óï¾ä½ÓÊÜÒ»¸ö»ò¶à¸ö·Ö×é¼ü×÷Ϊ²ÎÊý¡£ÕâЩ¼üÊÇÊý¾Ý¼¯ÖеÄÁУ¬ÓÃÓÚÈ·¶¨½«ÄÄЩÐзÖ×éÔÚÒ»Æð¡£
·Ö×éºó£¬SQL »áÕë¶Ôÿ¸ö×éÖ´ÐоۺϺ¯Êý£¬ÀýÈ磺
SUM£ºÅÌËã×éÖÐijÁеÄ×ܺÍ
COUNT£ºÅÌËã×éÖÐÐеÄÊýÄ¿
AVG£ºÅÌËã×éÖÐijÁеÄƽ¾ùÖµ
MIN£º²éÕÒ×éÖÐijÁеÄ×îСֵ
MAX£º²éÕÒ×éÖÐijÁеÄ×î´óÖµ
Óï·¨
GROUP BY Óï¾äµÄÓï·¨ÈçÏ£º
SELECT () FROM GROUP BY
µÇ¼ºó¸´ÖÆ
ʾÀý
ÒÔÏÂʾÀýÅÌËãÿ¸ö²úÆ·Àà±ðµÄÏúÊÛ¶î×ܺͣº
SELECT SUM(Sales) FROM Sales GROUP BY ProductCategory
µÇ¼ºó¸´ÖÆ
¸ÃÅÌÎʽ«·µ»ØÒ»¸ö°üÀ¨Ã¿¸ö²úÆ·ÖÖ±ð¼°ÆäÏìÓ¦ÏúÊÛ¶î×ܺ͵ÄÐÂÊý¾Ý¼¯¡£
ÒÔÉϾÍÊÇgroupbyÊÇʲôÒâ˼ÔÚsqlÖеÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡