{"id":621,"date":"2024-11-24T20:35:32","date_gmt":"2024-11-24T12:35:32","guid":{"rendered":"http:\/\/www.chan.ink\/?p=621"},"modified":"2024-11-24T20:42:51","modified_gmt":"2024-11-24T12:42:51","slug":"%e3%80%90mysql%e3%80%91group-by","status":"publish","type":"post","link":"http:\/\/www.chan.ink\/index.php\/2024\/11\/24\/%e3%80%90mysql%e3%80%91group-by\/","title":{"rendered":"\u3010MySQL\u3011group by"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\"><strong><code>GROUP BY<\/code> \u51b3\u5b9a\u5206\u7ec4\u7684\u903b\u8f91<\/strong>\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>GROUP BY<\/code> \u6307\u5b9a\u4e86\u5206\u7ec4\u7684\u4f9d\u636e\uff0c\u4e5f\u5c31\u662f\u8bf4\u5b83\u63a7\u5236\u54ea\u4e9b\u884c\u88ab\u5f52\u4e3a\u4e00\u7ec4\u3002<\/li>\n\n\n\n<li>\u53ea\u6709\u5728 <code>GROUP BY<\/code> \u4e2d\u6307\u5b9a\u7684\u5217\uff0c\u4ee5\u53ca\u901a\u8fc7\u805a\u5408\u51fd\u6570\u8ba1\u7b97\u5f97\u51fa\u7684\u5217\uff0c\u624d\u662f\u5408\u6cd5\u7684\u8f93\u51fa\u3002<\/li>\n\n\n\n<li>\u5982\u679c <code>SELECT<\/code> \u4e2d\u7684\u5217\u65e2\u4e0d\u5728 <code>GROUP BY<\/code> \u4e2d\uff0c\u4e5f\u4e0d\u901a\u8fc7\u805a\u5408\u51fd\u6570\u5904\u7406\uff0c\u5c31\u4f1a\u89e6\u53d1 MySQL \u7684 <code>ONLY_FULL_GROUP_BY<\/code> \u6a21\u5f0f\u9650\u5236\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u95ee\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">select student_id,student.sname,count(1),sum(num) from score left join student on score.student_id=student.sid group by student_id; \u53ef\u662f\u8fd9\u4e2a\u91cc\u9762\u7684student.sname\u4e0d\u662f\u4e0d\u5728group by\u4e2d\u4e48<app-translate-content _nghost-ng-c341168634=\"\" class=\"eusoft-translate-container-span-en ng-star-inserted\"><span _ngcontent-ng-c341168634=\"\" class=\"eusoft-eudic-chrome-extension-translate-content\"><span _ngcontent-ng-c341168634=\"\" class=\"eusoft-eudic-translate-loading-tag ng-star-inserted\" data-eusoft-eudic-loading-template-original-text=\"\u95eeselect student_id,student.sname,count(1),sum(num) from score left join student on score.student_id=student.sid group by student_id; \u53ef\u662f\u8fd9\u4e2a\u91cc\u9762\u7684student.sname\u4e0d\u662f\u4e0d\u5728group by\u4e2d\u4e48\"><\/span><\/span><\/app-translate-content><\/p>\n\n\n\n<h6 class=\"wp-block-heading\">ChatGPT \u8bf4<\/h6>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f60\u7684 SQL \u67e5\u8be2\u8bed\u53e5\u786e\u5b9e\u5728 <code>GROUP BY<\/code> \u5b50\u53e5\u4e2d\u6ca1\u6709\u5305\u542b <code>student.sname<\/code>\uff0c\u4f46\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u53ef\u4ee5\u8fd0\u884c\uff0c\u8fd9\u662f\u7531\u4e8e\u4ee5\u4e0b\u539f\u56e0\uff1a<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>\u4e3a\u4ec0\u4e48\u80fd\u8fd0\u884c\uff1f<\/strong><\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f60\u67e5\u8be2\u4e2d\u7684 <code>GROUP BY<\/code> \u662f\u57fa\u4e8e <code>student_id<\/code> \u7684\uff0c\u800c <code>student_id<\/code> \u548c <code>student.sname<\/code> \u5728\u903b\u8f91\u4e0a\u5177\u6709<strong>\u51fd\u6570\u4f9d\u8d56\u5173\u7cfb<\/strong>\u3002\u8fd9\u610f\u5473\u7740\uff0c\u5bf9\u4e8e\u6bcf\u4e2a\u552f\u4e00\u7684 <code>student_id<\/code>\uff0c\u4f1a\u6709\u4e14\u4ec5\u6709\u4e00\u4e2a\u5bf9\u5e94\u7684 <code>student.sname<\/code>\u3002MySQL \u5728\u5f00\u542f <code>ONLY_FULL_GROUP_BY<\/code> \u6a21\u5f0f\u65f6\uff0c\u5141\u8bb8\u8fd9\u6837\u7684\u8bed\u53e5\u901a\u8fc7\uff0c\u53ea\u8981\u672a\u51fa\u73b0\u5728 <code>GROUP BY<\/code> \u4e2d\u7684\u5217\u5177\u6709\u529f\u80fd\u4f9d\u8d56\u6027\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>GROUP BY \u51b3\u5b9a\u5206\u7ec4\u7684\u903b\u8f91\uff1a \u95ee\uff1a select student_id,student.sname,co [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-621","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/posts\/621","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/comments?post=621"}],"version-history":[{"count":2,"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/posts\/621\/revisions"}],"predecessor-version":[{"id":623,"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/posts\/621\/revisions\/623"}],"wp:attachment":[{"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/media?parent=621"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/categories?post=621"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/tags?post=621"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}