{"id":25900,"date":"2024-11-24T12:15:16","date_gmt":"2024-11-24T04:15:16","guid":{"rendered":"https:\/\/fwq.ai\/blog\/25900\/"},"modified":"2024-11-24T12:15:16","modified_gmt":"2024-11-24T04:15:16","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-mysql-update-%e8%af%ad%e5%8f%a5%e4%b8%8e-left-join-%e8%8e%b7%e5%8f%96%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%80%bc%ef%bc%9f-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/25900\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 MySQL update \u8bed\u53e5\u4e0e left join \u83b7\u53d6\u591a\u6761\u6570\u636e\u4e2d\u7684\u6700\u5927\u503c\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173072340330814.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 MySQL update \u8bed\u53e5\u4e0e left join \u83b7\u53d6\u591a\u6761\u6570\u636e\u4e2d\u7684\u6700\u5927\u503c\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 MySQL update \u8bed\u53e5\u4e0e left join \u83b7\u53d6\u591a\u6761\u6570\u636e\u4e2d\u7684\u6700\u5927\u503c\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong> \u6570\u636e\u5e93\u4e2d update \u8bed\u53e5 left join \u83b7\u53d6\u591a\u6761\u6570\u636e\u4e2d\u6700\u5927\u503c<\/strong><\/p>\n<p>mysql \u4e2d\u7684 update \u8bed\u53e5\u53ef\u4ee5\u7528\u4e8e\u66f4\u65b0\u8868\u4e2d\u7684\u6570\u636e\u3002\u5982\u679c\u9700\u8981\u66f4\u65b0\u67d0\u4e00\u5b57\u6bb5\u7684\u503c\u4e3a\u5176\u4ed6\u8868\u4e2d\u591a\u6761\u6570\u636e\u4e2d\u67d0\u5b57\u6bb5\u7684\u6700\u5927\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528 left join \u6765\u5b9e\u73b0\u3002<\/p>\n<p><strong>\u95ee\u9898\u80cc\u666f<\/strong><\/p>\n<p>\u6211\u4eec\u6709\u4e00\u5f20 student \u8868\uff0c\u5176\u4e2d\u5305\u542b\u5b66\u751f\u59d3\u540d name \u548c\u5206\u6570 score \u5b57\u6bb5\u3002\u8fd8\u6709\u4e00\u5f20 score \u8868\uff0c\u5176\u4e2d\u5305\u542b\u5b66\u751f\u7684\u5206\u6570\u8bb0\u5f55\uff0c\u6bcf\u4e2a\u5b66\u751f\u53ef\u80fd\u6709\u591a\u6b21\u5206\u6570\u8bb0\u5f55\u3002<\/p>\n<p><strong>\u66f4\u65b0\u8bed\u53e5<\/strong><\/p>\n<p>\u8981\u5c06 student \u8868\u4e2d score \u5b57\u6bb5\u66f4\u65b0\u4e3a score \u8868\u4e2d\u6bcf\u4e2a\u5b66\u751f\u7684\u6700\u9ad8\u5206\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b update \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><strong>left join \u7528\u6cd5<\/strong><\/p>\n<p>left join \u8bed\u6cd5\u5c06 student \u8868\u4e0e score \u8868\u8fde\u63a5\uff0c\u5e76\u8fd4\u56de student \u8868\u4e2d\u7684\u6240\u6709\u884c\uff0c\u5373\u4f7f\u8fd9\u4e9b\u884c\u5728 score \u8868\u4e2d\u6ca1\u6709\u5339\u914d\u9879\u3002\u5982\u679c student \u8868\u4e2d\u7684\u67d0\u4e00\u884c\u5728 score \u8868\u4e2d\u6709\u591a\u6761\u5339\u914d\u9879\uff0c\u5219 left join \u5c06\u8fd4\u56de\u5176\u4e2d\u5305\u542b\u6700\u5927\u5206\u6570\u7684\u90a3\u6761\u8bb0\u5f55\u3002<\/p>\n<p><strong>\u67e5\u8be2\u793a\u4f8b<\/strong><\/p>\n<p>\u66f4\u65b0\u540e\u7684 student \u8868\u5982\u4e0b\u6240\u793a\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 \u8bed\u53e5\u4e0e left join \u83b7\u53d6\u591a\u6761\u6570\u636e\u4e2d\u7684\u6700\u5927\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>\u6570\u636e\u5e93\u4e2d update \u8bed\u53e5 left join \u83b7\u53d6\u591a\u6761\u6570\u636e\u4e2d\u6700\u5927\u503c mysql \u4e2d\u7684 update \u8bed\u53e5\u53ef\u4ee5\u7528\u4e8e\u66f4\u65b0\u8868\u4e2d\u7684\u6570\u636e\u3002\u5982\u679c\u9700\u8981\u66f4\u65b0\u67d0\u4e00\u5b57\u6bb5\u7684\u503c\u4e3a\u5176\u4ed6\u8868\u4e2d\u591a\u6761\u6570\u636e\u4e2d\u67d0\u5b57\u6bb5\u7684\u6700\u5927\u503c\uff0c\u53ef\u4ee5\u4f7f\u7528 left join \u6765\u5b9e\u73b0\u3002 \u95ee\u9898\u80cc\u666f \u6211\u4eec\u6709\u4e00\u5f20 student \u8868\uff0c\u5176\u4e2d\u5305\u542b\u5b66\u751f\u59d3\u540d name \u548c\u5206\u6570 score \u5b57\u6bb5\u3002\u8fd8\u6709\u4e00\u5f20 score \u8868\uff0c\u5176\u4e2d\u5305\u542b\u5b66\u751f\u7684\u5206\u6570\u8bb0\u5f55\uff0c\u6bcf\u4e2a\u5b66\u751f\u53ef\u80fd\u6709\u591a\u6b21\u5206\u6570\u8bb0\u5f55\u3002 \u66f4\u65b0\u8bed\u53e5 \u8981\u5c06 student \u8868\u4e2d score \u5b57\u6bb5\u66f4\u65b0\u4e3a score \u8868\u4e2d\u6bcf\u4e2a\u5b66\u751f\u7684\u6700\u9ad8\u5206\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b update \u8bed\u53e5\uff1a update student set score = (select max(score) from score where score.student_id = student.id) \u767b\u5f55\u540e\u590d\u5236 left join \u7528\u6cd5 left join \u8bed\u6cd5\u5c06 student \u8868\u4e0e [&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-25900","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25900","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=25900"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/25900\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=25900"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=25900"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=25900"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}