{"id":631,"date":"2024-11-25T19:44:24","date_gmt":"2024-11-25T11:44:24","guid":{"rendered":"http:\/\/www.chan.ink\/?p=631"},"modified":"2024-11-25T19:46:32","modified_gmt":"2024-11-25T11:46:32","slug":"%e3%80%90mysql%e3%80%91%e8%ae%b0%e5%bd%95%e4%b8%80%e4%b8%aa%e5%b7%b2%e8%a7%a3%e5%86%b3%e4%bd%86%e5%be%85%e6%b7%b1%e5%85%a5%e7%9a%84%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/www.chan.ink\/index.php\/2024\/11\/25\/%e3%80%90mysql%e3%80%91%e8%ae%b0%e5%bd%95%e4%b8%80%e4%b8%aa%e5%b7%b2%e8%a7%a3%e5%86%b3%e4%bd%86%e5%be%85%e6%b7%b1%e5%85%a5%e7%9a%84%e9%97%ae%e9%a2%98\/","title":{"rendered":"\u3010MySQL\u3011\u8bb0\u5f55\u4e00\u4e2a\u5df2\u89e3\u51b3\u4f46\u5f85\u6df1\u5165\u7684\u95ee\u9898"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">mysql&gt; select student.sid,sname from student left join score on student.sid = score.student_id group by student_id having count(1) = 1;<br>ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column &#8216;day27db.student.sid&#8217; which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0a\u9762\u662f\u6700\u521d\u7684SQL\u8bed\u53e5\uff0c\u62a5\u9519\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u662fGPT\u7684\u56de\u7b54\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u867d\u7136 <strong><code>score.student_id<\/code> \u662f <code>student.sid<\/code> \u7684\u5916\u952e<\/strong>\uff0c\u4f46 MySQL <strong>\u4e0d\u4e00\u5b9a\u603b\u80fd\u81ea\u52a8\u63a8\u65ad\u8fd9\u79cd\u529f\u80fd\u4f9d\u8d56\u6027<\/strong>\u3002\u5f53 <code>ONLY_FULL_GROUP_BY<\/code> \u542f\u7528\u65f6\uff0cMySQL \u4f1a\u4e25\u683c\u68c0\u67e5\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>student.sid<\/code> \u548c <code>sname<\/code> \u662f\u5426\u5728 <code>GROUP BY<\/code> \u4e2d\u3002<\/li>\n\n\n\n<li>\u6216\u662f\u5426\u901a\u8fc7\u805a\u5408\u51fd\u6570\u5904\u7406\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u6ca1\u6709\u660e\u786e\u7684\u529f\u80fd\u4f9d\u8d56\u6027\uff0cMySQL \u4f1a\u62a5\u9519\uff0c\u56e0\u4e3a\u5b83\u65e0\u6cd5\u4fdd\u8bc1 <code>student.sid<\/code> \u548c <code>sname<\/code> \u7684\u503c\u5728\u5206\u7ec4\u4e2d\u662f\u552f\u4e00\u7684\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u53ef\u80fd\u7684\u539f\u56e0<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">MySQL \u7684\u7248\u672c\u548c\u4f18\u5316\u5668\u884c\u4e3a\u53ef\u80fd\u4e0d\u540c\u3002\u6709\u4e9b\u7248\u672c\u7684\u4f18\u5316\u5668\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\u53ef\u4ee5\u63a8\u65ad\u529f\u80fd\u4f9d\u8d56\u6027\uff0c\u800c\u6709\u4e9b\u60c5\u51b5\u4e0b\u4e0d\u80fd\u3002<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><\/app-translate-content><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4f18\u5316\u5668\u672a\u80fd\u63a8\u65ad\u51fa\u529f\u80fd\u4f9d\u8d56\u6027<\/strong>\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u867d\u7136\u5916\u952e\u7ea6\u675f\u5efa\u7acb\u4e86\u5173\u8054\uff0c\u4f46 <code>GROUP BY score.student_id<\/code> \u5e76\u672a\u76f4\u63a5\u5305\u542b <code>student.sid<\/code>\uff0c\u800c\u662f\u901a\u8fc7\u5916\u952e\u95f4\u63a5\u5173\u8054\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f18\u5316\u5668\u53ef\u80fd\u8ba4\u4e3a\u8fd9\u65e0\u6cd5\u4fdd\u8bc1\u552f\u4e00\u6027\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>\u4f9d\u8d56\u7248\u672c\u6216\u5b9e\u73b0<\/strong>\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u66f4\u6362\u4e3b\u8868\u53ca\u4ece\u8868\u7684\u4f4d\u7f6e\u540e\uff0c\u6b63\u5e38\u8fd0\u884c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">select student.sid,sname from student left join score on student.sid = score.student_id group by student_id having count(1) = 1;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">SELECT student.sid,student.sname FROM score LEFT JOIN student ON score.student_id = student.sid<br>GROUP BY student_id HAVING count( 1 ) =1;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u81f3\u4e8e\u8868\u7ed3\u6784\uff0c\u5982\u4e0b\u56fe\u6240\u793a:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><app-translate-content class=\"eusoft-translate-container-span-en ng-star-inserted\" _nghost-ng-c341168634=\"\"><\/app-translate-content><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1074\" height=\"702\" src=\"http:\/\/www.chan.ink\/wp-content\/uploads\/2024\/11\/11a3ea41460b41067fe3cef31cc358c.png\" alt=\"\" class=\"wp-image-632\"\/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>mysql&gt; select student.sid,sname from student left jo [&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-631","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/posts\/631","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=631"}],"version-history":[{"count":2,"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/posts\/631\/revisions"}],"predecessor-version":[{"id":634,"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/posts\/631\/revisions\/634"}],"wp:attachment":[{"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/media?parent=631"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/categories?post=631"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.chan.ink\/index.php\/wp-json\/wp\/v2\/tags?post=631"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}