{"id":25916,"date":"2024-11-24T15:58:50","date_gmt":"2024-11-24T07:58:50","guid":{"rendered":"https:\/\/fwq.ai\/blog\/25916\/"},"modified":"2024-11-24T15:58:50","modified_gmt":"2024-11-24T07:58:50","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-mysql-update-%e5%92%8c-left-join-%e6%9b%b4%e6%96%b0%e5%a4%9a%e6%9d%a1%e6%95%b0%e6%8d%ae%e4%b8%ad%e7%9a%84%e6%9c%80%e5%a4%a7%e5%ad%97%e6%ae%b5%e5%80%bc%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/25916\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 MySQL Update \u548c Left Join \u66f4\u65b0\u591a\u6761\u6570\u636e\u4e2d\u7684\u6700\u5927\u5b57\u6bb5\u503c\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173072541697522.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 MySQL Update \u548c Left Join \u66f4\u65b0\u591a\u6761\u6570\u636e\u4e2d\u7684\u6700\u5927\u5b57\u6bb5\u503c\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 MySQL Update \u548c Left Join \u66f4\u65b0\u591a\u6761\u6570\u636e\u4e2d\u7684\u6700\u5927\u5b57\u6bb5\u503c\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong> update \u8bed\u53e5\u4f7f\u7528 left join \u66f4\u65b0\u591a\u6761\u6570\u636e\u4e2d\u7684\u6700\u5927\u5b57\u6bb5\u503c<\/strong><\/p>\n<p>\u5728\u5173\u7cfb\u578b\u6570\u636e\u5e93\u4e2d\uff0c\u6709\u65f6\u5019\u9700\u8981\u66f4\u65b0\u8868\u4e2d\u7684\u67d0\u4e00\u5217\u4e3a\u5176\u4ed6\u8868\u4e2d\u76f8\u5173\u884c\u7684\u6700\u5927\u503c\u3002\u5bf9\u4e8e mysql \u800c\u8a00\uff0c\u53ef\u4ee5\u4f7f\u7528 left join \u6765\u5b9e\u73b0\u8fd9\u6837\u7684\u66f4\u65b0\u64cd\u4f5c\u3002<\/p>\n<p>\u8003\u8651\u6211\u4eec\u6709\u4ee5\u4e0b\u4e24\u4e2a\u8868\uff1a<\/p>\n<p><strong>student \u8868<\/strong><\/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><strong>score \u8868<\/strong><\/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\u5c06 student \u8868\u4e2d\u6bcf\u4e2a\u5b66\u751f\u7684 score \u5b57\u6bb5\u66f4\u65b0\u4e3a\u5176\u5728 score \u8868\u4e2d\u5bf9\u5e94\u7684\u6700\u5927\u503c\u3002<\/p>\n<p>\u4e3a\u4e86\u4f7f\u7528 left join \u6765\u5b9e\u73b0\u6b64\u66f4\u65b0\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528\u4ee5\u4e0b sql \u8bed\u53e5\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>\u5728\u8fd9\u4e2a\u8bed\u53e5\u4e2d\uff1a<\/p>\n<ul>\n<li>update student \u90e8\u5206\u6307\u5b9a\u8981\u66f4\u65b0\u7684\u8868\u662f student \u8868\u3002<\/li>\n<li>set score=(select max(score) from score where score.student_id=student.id) \u90e8\u5206\u5b9a\u4e49\u4e86\u8981\u66f4\u65b0\u7684\u5b57\u6bb5\u503c\u3002<\/li>\n<li>\u5b50\u67e5\u8be2 (select max(score) from score where score.student_id=student.id) \u4ece score \u8868\u4e2d\u9009\u62e9\u6bcf\u4e2a\u5b66\u751f\u7684\u6700\u5927\u5206\u503c\uff0c\u5176\u4e2d where \u5b50\u53e5\u786e\u4fdd\u53ea\u9009\u62e9\u4e0e\u5b66\u751f\u5339\u914d\u7684\u5206\u503c\u3002<\/li>\n<\/ul>\n<p>\u6267\u884c\u6b64\u8bed\u53e5\u540e\uff0cstudent \u8868\u4e2d\u6bcf\u4e2a\u5b66\u751f\u7684 score \u5b57\u6bb5\u5c06\u66f4\u65b0\u4e3a\u5176\u5728 score \u8868\u4e2d\u5bf9\u5e94\u7684\u6700\u5927\u503c\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>80<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td>\u5c0f\u7ea2<\/td>\n<td>98<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 MySQL Update \u548c Left Join \u66f4\u65b0\u591a\u6761\u6570\u636e\u4e2d\u7684\u6700\u5927\u5b57\u6bb5\u503c\uff1f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>update \u8bed\u53e5\u4f7f\u7528 left join \u66f4\u65b0\u591a\u6761\u6570\u636e\u4e2d\u7684\u6700\u5927\u5b57\u6bb5\u503c \u5728\u5173\u7cfb\u578b\u6570\u636e\u5e93\u4e2d\uff0c\u6709\u65f6\u5019\u9700\u8981\u66f4\u65b0\u8868\u4e2d\u7684\u67d0\u4e00\u5217\u4e3a\u5176\u4ed6\u8868\u4e2d\u76f8\u5173\u884c\u7684\u6700\u5927\u503c\u3002\u5bf9\u4e8e mysql \u800c\u8a00\uff0c\u53ef\u4ee5\u4f7f\u7528 left join \u6765\u5b9e\u73b0\u8fd9\u6837\u7684\u66f4\u65b0\u64cd\u4f5c\u3002 \u8003\u8651\u6211\u4eec\u6709\u4ee5\u4e0b\u4e24\u4e2a\u8868\uff1a student \u8868 id name score 1 \u5c0f\u660e null 2 \u5c0f\u7ea2 null score \u8868 id student_id score 1 1 80 2 2 88 3 1 78 4 2 98 \u6211\u4eec\u7684\u76ee\u6807\u662f\u5c06 student \u8868\u4e2d\u6bcf\u4e2a\u5b66\u751f\u7684 score \u5b57\u6bb5\u66f4\u65b0\u4e3a\u5176\u5728 score \u8868\u4e2d\u5bf9\u5e94\u7684\u6700\u5927\u503c\u3002 \u4e3a\u4e86\u4f7f\u7528 left join \u6765\u5b9e\u73b0\u6b64\u66f4\u65b0\uff0c\u6211\u4eec\u9700\u8981\u4f7f\u7528\u4ee5\u4e0b sql \u8bed\u53e5\uff1a update student [&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-25916","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25916","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=25916"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25916\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=25916"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=25916"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=25916"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}