{"id":7066,"date":"2024-11-14T12:13:25","date_gmt":"2024-11-14T04:13:25","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7066\/"},"modified":"2024-11-14T12:13:25","modified_gmt":"2024-11-14T04:13:25","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-sql-%e5%b0%86%e8%ae%be%e5%a4%87%e7%b1%bb%e5%88%ab%e5%90%8d%e7%a7%b0%e5%a1%ab%e5%85%85%e5%88%b0%e8%ae%be%e5%a4%87%e8%a1%a8%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7066\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 SQL \u5c06\u8bbe\u5907\u7c7b\u522b\u540d\u79f0\u586b\u5145\u5230\u8bbe\u5907\u8868\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173037406758102.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 SQL \u5c06\u8bbe\u5907\u7c7b\u522b\u540d\u79f0\u586b\u5145\u5230\u8bbe\u5907\u8868\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 SQL \u5c06\u8bbe\u5907\u7c7b\u522b\u540d\u79f0\u586b\u5145\u5230\u8bbe\u5907\u8868\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u901a\u8fc7 sql \u586b\u5145\u53d8\u66f4\u540e\u7684\u8868\u683c\u6570\u636e<\/strong><\/p>\n<p>\u5df2\u77e5\u7cfb\u7edf\u5b58\u5728\u8bbe\u5907\u7c7b\u522b\u8868 device_category \u4e0e\u8bbe\u5907\u8868 device\uff0c\u9700\u6c42\u53d8\u66f4\u4e3a\u5728 device \u8868\u4e2d\u5197\u4f59\u5b58\u50a8 device_category_name \u5b57\u6bb5\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u901a\u8fc7 sql \u67e5\u8be2\u586b\u5145\u65b0\u589e\u5b57\u6bb5\u7684\u6570\u636e\u3002<\/p>\n<p><strong>sql \u67e5\u8be2<\/strong><\/p>\n<pre>-- \u6dfb\u52a0\u8bbe\u5907\u7c7b\u522b\u540d\u79f0\u5217\nALTER TABLE device ADD COLUMN device_category_name VARCHAR(100);\n\n-- \u586b\u5145\u6570\u636e\nUPDATE device, device_category AS dc SET device.device_category_name = dc.name\nWHERE dc.id = device.device_category_id;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u6267\u884c\u6b65\u9aa4<\/strong><\/p>\n<ol>\n<li> <strong>\u6dfb\u52a0\u5217<\/strong>\uff1a\u4f7f\u7528 alter table \u8bed\u53e5\u6dfb\u52a0 device_category_name \u5217\u3002<\/li>\n<li> <strong>\u586b\u5145\u6570\u636e<\/strong>\uff1a\u4f7f\u7528 update \u548c join \u8bed\u53e5\u4ece device_category \u8868\u4e2d\u83b7\u53d6\u7c7b\u522b\u540d\u79f0\u5e76\u5c06\u5176\u586b\u5145\u5230 device \u8868\u7684 device_category_name \u5217\u4e2d\u3002<\/li>\n<\/ol>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<p>\u5728\u6267\u884c\u4efb\u4f55\u66f4\u65b0\u64cd\u4f5c\u524d\uff0c\u8bf7\u52a1\u5fc5\u5907\u4efd\u6570\u636e\u3002<\/p>\n<p><strong>\u6f14\u793a<\/strong><\/p>\n<p>\u5728\u7ebf\u6d4b\u8bd5\u5730\u5740\uff1ahttp:\/\/sqlfiddle.com\/#!9\/628d9f\/1<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 SQL \u5c06\u8bbe\u5907\u7c7b\u522b\u540d\u79f0\u586b\u5145\u5230\u8bbe\u5907\u8868\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>\u5982\u4f55\u901a\u8fc7 sql \u586b\u5145\u53d8\u66f4\u540e\u7684\u8868\u683c\u6570\u636e \u5df2\u77e5\u7cfb\u7edf\u5b58\u5728\u8bbe\u5907\u7c7b\u522b\u8868 device_category \u4e0e\u8bbe\u5907\u8868 device\uff0c\u9700\u6c42\u53d8\u66f4\u4e3a\u5728 device \u8868\u4e2d\u5197\u4f59\u5b58\u50a8 device_category_name \u5b57\u6bb5\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u901a\u8fc7 sql \u67e5\u8be2\u586b\u5145\u65b0\u589e\u5b57\u6bb5\u7684\u6570\u636e\u3002 sql \u67e5\u8be2 &#8212; \u6dfb\u52a0\u8bbe\u5907\u7c7b\u522b\u540d\u79f0\u5217 ALTER TABLE device ADD COLUMN device_category_name VARCHAR(100); &#8212; \u586b\u5145\u6570\u636e UPDATE device, device_category AS dc SET device.device_category_name = dc.name WHERE dc.id = device.device_category_id; \u767b\u5f55\u540e\u590d\u5236 \u6267\u884c\u6b65\u9aa4 \u6dfb\u52a0\u5217\uff1a\u4f7f\u7528 alter table \u8bed\u53e5\u6dfb\u52a0 device_category_name \u5217\u3002 \u586b\u5145\u6570\u636e\uff1a\u4f7f\u7528 update \u548c join \u8bed\u53e5\u4ece device_category \u8868\u4e2d\u83b7\u53d6\u7c7b\u522b\u540d\u79f0\u5e76\u5c06\u5176\u586b\u5145\u5230 device [&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-7066","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7066","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=7066"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7066\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7066"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7066"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7066"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}