{"id":7662,"date":"2024-11-14T16:46:58","date_gmt":"2024-11-14T08:46:58","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7662\/"},"modified":"2024-11-14T16:46:58","modified_gmt":"2024-11-14T08:46:58","slug":"mysql-%e4%b8%ad%e7%9a%84-group-by-%e8%af%ad%e5%8f%a5%e4%b8%ba%e4%bb%80%e4%b9%88%e6%9c%89%e6%97%b6%e4%b8%8d%e4%b8%a5%e6%a0%bc%e8%a6%81%e6%b1%82%e6%89%80%e6%9c%89%e5%ad%97%e6%ae%b5%e9%83%bd%e5%8c%85","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7662\/","title":{"rendered":"MySQL \u4e2d\u7684 GROUP BY \u8bed\u53e5\u4e3a\u4ec0\u4e48\u6709\u65f6\u4e0d\u4e25\u683c\u8981\u6c42\u6240\u6709\u5b57\u6bb5\u90fd\u5305\u542b\u5728\u5185\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173112464220961.jpg\" class=\"aligncenter\" title=\"MySQL \u4e2d\u7684 GROUP BY \u8bed\u53e5\u4e3a\u4ec0\u4e48\u6709\u65f6\u4e0d\u4e25\u683c\u8981\u6c42\u6240\u6709\u5b57\u6bb5\u90fd\u5305\u542b\u5728\u5185\uff1f\u63d2\u56fe\" alt=\"MySQL \u4e2d\u7684 GROUP BY \u8bed\u53e5\u4e3a\u4ec0\u4e48\u6709\u65f6\u4e0d\u4e25\u683c\u8981\u6c42\u6240\u6709\u5b57\u6bb5\u90fd\u5305\u542b\u5728\u5185\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 MySQL \u4e2d\u4f7f\u7528 GROUP BY\uff1f<\/strong><\/p>\n<p>\u4e0d\u5c11\u5f00\u53d1\u8005\u53d1\u73b0\uff0cMySQL \u7684 GROUP BY \u8bed\u53e5\u5e76\u4e0d\u603b\u662f\u4e25\u683c\u8981\u6c42\u5c06 SELECT \u8bed\u53e5\u4e2d\u6240\u6709\u7684\u5b57\u6bb5\u90fd\u5305\u542b\u5728 GROUP BY \u5b50\u53e5\u4e2d\u3002\u8fd9\u7a76\u7adf\u662f\u600e\u4e48\u56de\u4e8b\u5462\uff1f<\/p>\n<p>\u4e8b\u5b9e\u4e0a\uff0cMySQL \u7684\u884c\u4e3a\u53d6\u51b3\u4e8e SQL_MODE \u7684\u8bbe\u7f6e\u3002\u4ece MySQL 5.7 \u5f00\u59cb\uff0c\u9ed8\u8ba4\u7684 SQL_MODE \u542f\u7528\u4e86 ONLY_FULL_GROUP_BY \u9009\u9879\u3002\u5f53\u6b64\u9009\u9879\u542f\u7528\u65f6\uff0cSELECT \u8bed\u53e5\u4e2d\u672a\u51fa\u73b0\u5728 GROUP BY \u5b50\u53e5\u4e2d\u7684\u5217\u5fc5\u987b\u5728\uff08\u5982 SUM\u3001COUNT\u3001AVG\uff09\u4e2d\u4f7f\u7528\uff0c\u5426\u5219\u4f1a\u629b\u51fa\u9519\u8bef\u3002<\/p>\n<p>\u4e0d\u8fc7\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u624b\u52a8\u8c03\u6574 SQL_MODE \u8bbe\u7f6e\u6765\u7981\u7528 ONLY_FULL_GROUP_BY \u9009\u9879\u3002\u7981\u7528\u540e\uff0cMySQL \u4e0d\u518d\u68c0\u67e5 SELECT \u8bed\u53e5\u4e2d\u7684\u5217\u662f\u5426\u5168\u90e8\u5305\u542b\u5728 GROUP BY \u5b50\u53e5\u4e2d\u3002<\/p>\n<p>\u6709\u5173\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605 MySQL 5.7 \u53c2\u8003\u624b\u518c\uff1a<\/p>\n<ul>\n<li>MySQL :: MySQL 5.7 Reference Manual :: 1.3 What Is New in MySQL 5.7<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fMySQL \u4e2d\u7684 GROUP BY \u8bed\u53e5\u6709\u65f6\u4e0d\u4e25\u683c\u8981\u6c42\u6240\u6709\u5b57\u6bb5\u90fd\u5305\u542b\u5728\u5185\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5728 MySQL \u4e2d\u4f7f\u7528 GROUP BY\uff1f \u4e0d\u5c11\u5f00\u53d1\u8005\u53d1\u73b0\uff0cMySQL \u7684 GROUP BY \u8bed\u53e5\u5e76\u4e0d\u603b\u662f\u4e25\u683c\u8981\u6c42\u5c06 SELECT \u8bed\u53e5\u4e2d\u6240\u6709\u7684\u5b57\u6bb5\u90fd\u5305\u542b\u5728 GROUP BY \u5b50\u53e5\u4e2d\u3002\u8fd9\u7a76\u7adf\u662f\u600e\u4e48\u56de\u4e8b\u5462\uff1f \u4e8b\u5b9e\u4e0a\uff0cMySQL \u7684\u884c\u4e3a\u53d6\u51b3\u4e8e SQL_MODE \u7684\u8bbe\u7f6e\u3002\u4ece MySQL 5.7 \u5f00\u59cb\uff0c\u9ed8\u8ba4\u7684 SQL_MODE \u542f\u7528\u4e86 ONLY_FULL_GROUP_BY \u9009\u9879\u3002\u5f53\u6b64\u9009\u9879\u542f\u7528\u65f6\uff0cSELECT \u8bed\u53e5\u4e2d\u672a\u51fa\u73b0\u5728 GROUP BY \u5b50\u53e5\u4e2d\u7684\u5217\u5fc5\u987b\u5728\uff08\u5982 SUM\u3001COUNT\u3001AVG\uff09\u4e2d\u4f7f\u7528\uff0c\u5426\u5219\u4f1a\u629b\u51fa\u9519\u8bef\u3002 \u4e0d\u8fc7\uff0c\u4f60\u53ef\u4ee5\u901a\u8fc7\u624b\u52a8\u8c03\u6574 SQL_MODE \u8bbe\u7f6e\u6765\u7981\u7528 ONLY_FULL_GROUP_BY \u9009\u9879\u3002\u7981\u7528\u540e\uff0cMySQL \u4e0d\u518d\u68c0\u67e5 SELECT \u8bed\u53e5\u4e2d\u7684\u5217\u662f\u5426\u5168\u90e8\u5305\u542b\u5728 GROUP BY \u5b50\u53e5\u4e2d\u3002 \u6709\u5173\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605 MySQL 5.7 \u53c2\u8003\u624b\u518c\uff1a MySQL :: MySQL 5.7 Reference Manual :: 1.3 What [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-7662","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7662","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=7662"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7662\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7662"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7662"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7662"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}