{"id":4103,"date":"2020-08-19T10:41:14","date_gmt":"2020-08-19T02:41:14","guid":{"rendered":"https:\/\/www.webteach.tw\/?p=4103"},"modified":"2020-08-19T10:41:14","modified_gmt":"2020-08-19T02:41:14","slug":"1055","status":"publish","type":"post","link":"https:\/\/www.webteach.tw\/?p=4103","title":{"rendered":"[ MySQL ] &#8211; How to fix error #1055 \u5982\u4f55\u89e3\u6c7a group by \u9078\u53d6\u6b04\u4f4d\u975e\u529f\u80fd\u51fd\u5f0f"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">\u5176\u5be6\u9019\u500b\u554f\u984c\u5c0f\u7de8\u8001\u65e9\u5c31\u9047\u904e\u4e86\uff0c\u4f46\u662f\u7576\u6642\u554f\u984c\u89e3\u6c7a\u5f8c\u6c92\u6709\u5beb\u4e0b\u7b46\u8a18\u6240\u4ee5\u53c8\u91cd\u65b0\u627e\u4e86\u4e00\u6b21\u89e3\u6cd5\uff0c\u679c\u7136\u8a8d\u771f\u5beb\u7b46\u8a18\u662f\u5fc5\u8981\u7684\u514d\u7684\u591a\u82b1\u4e00\u4e9b\u7121\u754f\u7684\u6642\u9593\u53bb\u505a\u91cd\u8986\u7684\u4e8b\uff0c\u9019\u6a23\u6211\u7684\u7522\u503c\u5c31\u4e0b\u964d\u4e86\uff1b\u554f\u984c\u5c31\u662f group by \u9078\u53d6\u6b04\u4f4d\u975e\u529f\u80fd\u51fd\u5f0f\uff0c\u6703\u51fa\u73fe error #1055 \uff0c\u89e3\u6cd5\u4e5f\u5f88\u7c21\u55ae\u8a2d\u5b9a\u76f8\u95dc\u53c3\u6578\u5373\u53ef\u3002<\/p>\n\n\n<p class=\"wp-block-paragraph\">\u9019\u6a23\u662f\u53ef\u4ee5\u67e5\u8a62\u7684<\/p>\n\n\n<pre class=\"wp-block-code\"><code>select id, max(time) from table where age>'30' group by id;<\/code><\/pre>\n\n\n<p class=\"wp-block-paragraph\">\u4f46\u662f\u9019\u6a23\u591a\u500b\u6b04\u4f4d\u5c31\u6703\u51fa\u73fe\u932f\u8aa4<\/p>\n\n\n<pre class=\"wp-block-code\"><code>select id, max(time),name from table where age>'30' group by id;<\/code><\/pre>\n\n\n<p class=\"wp-block-paragraph\">\u932f\u8aa4\u8a0a\u606f<\/p>\n\n\n<h5 class=\"wp-block-heading\">1055 &#8211; Expression #3 of SELECT list is not in GROUP BY clause and contains nonaggregated column &#8216;db.table.columns&#8217; which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by<\/h5>\n\n\n<p class=\"wp-block-paragraph\">\u9810\u8a2d\u7684\u67e5\u8a62\u6a21\u5f0f\u53ea\u80fd\u986f\u793a group by \u6b04\u4f4d\uff0c\u5176\u5b83\u7684\u90fd\u53ea\u80fd\u662f\u529f\u80fd\u51fd\u5f0f<\/p>\n\n\n<p class=\"wp-block-paragraph\">\u89e3\u6c7a\u65b9\u6cd5\uff1a<br \/>\u53bbmysql\u505c\u7528 only_full_group_by \u8a2d\u5b9a<\/p>\n\n\n<pre class=\"wp-block-code\"><code>mysql -u root -p\nmysql> SET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));\nQuery OK, 0 rows affected (0.00 sec)<\/code><\/pre>\n\n\n<p class=\"wp-block-paragraph\">\u53c3\u8003\u7db2\u5740\uff1a<br \/><a href=\"https:\/\/stackoverflow.com\/questions\/23921117\/disable-only-full-group-by\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/stackoverflow.com\/questions\/23921117\/disable-only-full-group-b<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5176\u5be6\u9019\u500b\u554f\u984c\u5c0f\u7de8\u8001\u65e9\u5c31\u9047\u904e\u4e86\uff0c\u4f46\u662f\u7576\u6642\u554f\u984c\u89e3\u6c7a\u5f8c\u6c92\u6709\u5beb\u4e0b\u7b46\u8a18\u6240\u4ee5\u53c8\u91cd\u65b0\u627e\u4e86\u4e00\u6b21\u89e3\u6cd5\uff0c\u679c\u7136\u8a8d\u771f\u5beb\u7b46\u8a18\u662f\u5fc5\u8981\u7684\u514d\u7684\u591a\u82b1\u4e00\u4e9b\u7121\u754f\u7684\u6642\u9593\u53bb\u505a\u91cd\u8986\u7684\u4e8b\uff0c\u9019\u6a23\u6211\u7684\u7522\u503c\u5c31\u4e0b\u964d\u4e86\uff1b\u554f\u984c\u5c31\u662f group by \u9078\u53d6\u6b04\u4f4d\u975e\u529f\u80fd\u51fd\u5f0f\uff0c\u6703\u51fa\u73fe error #1055 \uff0c\u89e3\u6cd5\u4e5f\u5f88\u7c21\u55ae\u8a2d\u5b9a\u76f8\u95dc\u53c3\u6578\u5373\u53ef\u3002<\/p>\n","protected":false},"author":1,"featured_media":1867,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[60,241,291,402,427],"class_list":["post-4103","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mysql","tag-60","tag-error","tag-group-by","tag-mysql","tag-only_full_group_by","hvn-theme-has-thumbnail"],"_links":{"self":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/4103","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4103"}],"version-history":[{"count":0,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/posts\/4103\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=\/wp\/v2\/media\/1867"}],"wp:attachment":[{"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4103"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4103"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.webteach.tw\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4103"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}