{"id":200948,"date":"2025-05-06T14:51:21","date_gmt":"2025-05-06T06:51:21","guid":{"rendered":"https:\/\/server.hk\/cnblog\/200948\/"},"modified":"2025-05-06T14:51:21","modified_gmt":"2025-05-06T06:51:21","slug":"mysql-update-left-join-%e6%9b%b4%e6%96%b0%e6%9c%80%e5%a4%a7%e5%80%bc%ef%bc%9a%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8%e5%ad%90%e6%9f%a5%e8%af%a2%e4%bb%8e%e5%a4%9a%e6%9d%a1%e6%95%b0%e6%8d%ae%e4%b8%ad","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/200948\/","title":{"rendered":"MySQL Update Left Join \u66f4\u65b0\u6700\u5927\u503c\uff1a\u5982\u4f55\u4f7f\u7528\u5b50\u67e5\u8be2\u4ece\u591a\u6761\u6570\u636e\u4e2d\u83b7\u53d6\u6700\u5927\u503c\u5e76\u66f4\u65b0\u7279\u5b9a\u5b57\u6bb5\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<h1>MySQL Update Left Join \u66f4\u65b0\u6700\u5927\u503c\uff1a\u5982\u4f55\u4f7f\u7528\u5b50\u67e5\u8be2\u4ece\u591a\u6761\u6570\u636e\u4e2d\u83b7\u53d6\u6700\u5927\u503c\u5e76\u66f4\u65b0\u7279\u5b9a\u5b57\u6bb5\uff1f<\/h1>\n<p>\u672c\u7bc7\u6587\u7ae0\u5411\u5927\u5bb6\u4ecb\u7ecd\u300aMySQL Update Left Join \u66f4\u65b0\u6700\u5927\u503c\uff1a\u5982\u4f55\u4f7f\u7528\u5b50\u67e5\u8be2\u4ece\u591a\u6761\u6570\u636e\u4e2d\u83b7\u53d6\u6700\u5927\u503c\u5e76\u66f4\u65b0\u7279\u5b9a\u5b57\u6bb5\uff1f\u300b\uff0c\u4e3b\u8981\u5305\u62ec\uff0c\u5177\u6709\u4e00\u5b9a\u7684\u53c2\u8003\u4ef7\u503c\uff0c\u9700\u8981\u7684\u670b\u53cb\u53ef\u4ee5\u53c2\u8003\u4e00\u4e0b\u3002<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241122\/1732276456674070e85d41c.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>mysql update left join \u66f4\u65b0\u6700\u5927\u503c<\/strong><\/p>\n<p><strong>\u95ee\u9898\uff1a<\/strong><\/p>\n<p>\u5982\u4f55\u4f7f\u7528 mysql update \u8bed\u53e5\u548c left join \u4ece\u591a\u6761\u6570\u636e\u4e2d\u83b7\u53d6\u6700\u5927\u503c\u5e76\u66f4\u65b0\u53e6\u4e00\u4e2a\u8868\u7684\u7279\u5b9a\u5b57\u6bb5\uff1f<\/p>\n<p><strong>\u4f8b\u5b50\uff1a<\/strong><\/p>\n<p>\u6211\u4eec\u6709 student \u8868\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>id<\/th>\n<th>name<\/th>\n<th>score<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>\u5c0f\u660e<\/td>\n<td>null<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>\u5c0f\u7ea2<\/td>\n<td>null<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4ee5\u53ca score \u8868\uff1a<\/p>\n<table>\n<thead>\n<tr>\n<th>id<\/th>\n<th>student_id<\/th>\n<th>score<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>1<\/td>\n<td>1<\/td>\n<td>80<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>2<\/td>\n<td>88<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td>1<\/td>\n<td>78<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td>2<\/td>\n<td>98<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u6211\u4eec\u7684\u76ee\u6807\u662f\u66f4\u65b0 student \u8868\u7684 score \u5b57\u6bb5\u4e3a score \u8868\u4e2d\u6bcf\u4e2a student_id \u5bf9\u5e94\u7684\u6700\u5927 score \u503c\u3002<\/p>\n<p><strong>\u89e3\u7b54\uff1a<\/strong><\/p>\n<p>\u4f7f\u7528 left join \u548c\u5b50\u67e5\u8be2\u53ef\u4ee5\u5b9e\u73b0\u6b64\u76ee\u7684\uff1a<\/p>\n<pre>update student set score=(select max(score) from score where score.student_id=student.id)<\/pre>\n<p><strong>\u89e3\u91ca\uff1a<\/strong><\/p>\n<ul>\n<li>left join \u5c06 student \u8868\u4e0e score \u8868\u8fde\u63a5\uff0c\u5176\u4e2d student.id \u4e0e score.student_id \u5339\u914d\u3002<\/li>\n<li>\u5b50\u67e5\u8be2 max(score) \u83b7\u53d6 score.student_id \u4e0e student.id \u76f8\u5339\u914d\u7684\u6240\u6709 score \u503c\u7684\u6700\u5927\u503c\u3002<\/li>\n<li>update \u8bed\u53e5\u5c06 student.score \u5b57\u6bb5\u66f4\u65b0\u4e3a\u8be5\u6700\u5927\u503c\u3002<\/li>\n<\/ul>\n<p>\u4eca\u5929\u5173\u4e8e\u300aMySQL Update Left Join \u66f4\u65b0\u6700\u5927\u503c\uff1a\u5982\u4f55\u4f7f\u7528\u5b50\u67e5\u8be2\u4ece\u591a\u6761\u6570\u636e\u4e2d\u83b7\u53d6\u6700\u5927\u503c\u5e76\u66f4\u65b0\u7279\u5b9a\u5b57\u6bb5\uff1f\u300b\u7684\u5185\u5bb9\u4ecb\u7ecd\u5c31\u5230\u6b64\u7ed3\u675f\uff0c\u5982\u679c\u6709\u4ec0\u4e48\u7591\u95ee\u6216\u8005\u5efa\u8bae\uff0c\u53ef\u4ee5\u5728\u4e3b\u673a\u5b9d\u8d1d\u516c\u4f17\u53f7\u4e0b\u591a\u591a\u56de\u590d\u4ea4\u6d41\uff1b\u6587\u4e2d\u82e5\u6709\u4e0d\u6b63\u4e4b\u5904\uff0c\u4e5f\u5e0c\u671b\u56de\u590d\u7559\u8a00\u4ee5\u544a\u77e5\uff01<\/p>\n<dl>\n<dt>\n <\/dt>\n<\/dl>\n","protected":false},"excerpt":{"rendered":"<p>MySQL Update Lef&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-200948","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200948","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=200948"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/200948\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=200948"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=200948"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=200948"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}