{"id":7330,"date":"2024-11-14T09:10:31","date_gmt":"2024-11-14T01:10:31","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7330\/"},"modified":"2024-11-14T09:10:31","modified_gmt":"2024-11-14T01:10:31","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:\/\/fwq.ai\/blog\/7330\/","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><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173071392537233.jpg\" class=\"aligncenter\" title=\"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\u63d2\u56fe\" alt=\"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\u63d2\u56fe\" \/><\/p>\n<p><strong> 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> \u767b\u5f55\u540e\u590d\u5236 <\/p>\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>\u4ee5\u4e0a\u5c31\u662fMySQL 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\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>update left join \u66f4\u65b0\u6700\u5927\u503c \u95ee\u9898\uff1a \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 \u4f8b\u5b50\uff1a \u6211\u4eec\u6709 student \u8868\uff1a id name score 1 \u5c0f\u660e null 2 \u5c0f\u7ea2 null \u4ee5\u53ca score \u8868\uff1a id student_id score 1 1 80 2 2 88 3 1 78 4 2 98 \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 \u89e3\u7b54\uff1a [&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-7330","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7330","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=7330"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7330\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7330"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7330"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7330"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}