{"id":7115,"date":"2024-11-14T10:24:29","date_gmt":"2024-11-14T02:24:29","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7115\/"},"modified":"2024-11-14T10:24:29","modified_gmt":"2024-11-14T02:24:29","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-mysql-%e6%9f%a5%e8%af%a2%e6%a0%91%e7%8a%b6%e7%bb%93%e6%9e%84%e6%95%b0%e6%8d%ae%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7115\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 MySQL \u67e5\u8be2\u6811\u72b6\u7ed3\u6784\u6570\u636e\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173045520665742.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 MySQL \u67e5\u8be2\u6811\u72b6\u7ed3\u6784\u6570\u636e\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 MySQL \u67e5\u8be2\u6811\u72b6\u7ed3\u6784\u6570\u636e\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728  \u4e2d\u67e5\u8be2\u6811\u72b6\u7ed3\u6784\u6570\u636e<\/strong><\/p>\n<p>\u6811\u72b6\u7ed3\u6784\u6570\u636e\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u6570\u636e\u5b58\u50a8\u65b9\u5f0f\uff0c\u7528\u4e8e\u8868\u793a\u5177\u6709\u5c42\u6b21\u5173\u7cfb\u7684\u6570\u636e\u3002\u4f8b\u5982\uff0c\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684\u6587\u4ef6\u548c\u6587\u4ef6\u5939\u53ef\u4ee5\u8868\u793a\u4e3a\u4e00\u68f5\u6811\u3002<\/p>\n<p>\u8981\u67e5\u8be2\u6811\u72b6\u7ed3\u6784\u6570\u636e\uff0c\u6211\u4eec\u9700\u8981\u4e00\u79cd\u65b9\u6cd5\u6765\u8868\u793a\u6811\u4e2d\u7684\u5c42\u6b21\u5173\u7cfb\u3002\u4e00\u79cd\u5e38\u89c1\u7684\u6280\u672f\u662f\u4f7f\u7528\u201c\u95ed\u5305\u8868\u201d\u3002<\/p>\n<p><strong>\u4ec0\u4e48\u662f\u95ed\u5305\u8868\uff1f<\/strong><\/p>\n<p>\u95ed\u5305\u8868\u662f\u4e00\u4e2a\u6269\u5c55\u4e86\u6811\u72b6\u7ed3\u6784\u7684\u8868\uff0c\u5b83\u5305\u542b\u989d\u5916\u7684\u5217\u6765\u8ddf\u8e2a\u6bcf\u4e2a\u8282\u70b9\u5230\u5176\u6240\u6709\u7956\u5148\u7684\u8ddd\u79bb\u3002\u8fd9\u4f7f\u5f97\u67e5\u8be2\u6811\u4e2d\u7684\u6240\u6709\u8282\u70b9\u53d8\u5f97\u5f88\u5bb9\u6613\uff0c\u5373\u4f7f\u8fd9\u4e9b\u8282\u70b9\u5728\u67e5\u8be2\u4e2d\u6ca1\u6709\u660e\u786e\u6307\u5b9a\u3002<\/p>\n<p><strong>\u521b\u5efa\u95ed\u5305\u8868<\/strong><\/p>\n<p>\u8981\u521b\u5efa\u95ed\u5305\u8868\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b sql \u8bed\u53e5\uff1a<\/p>\n<pre>create table tree(\n  self int,\n  parent int,\n  distance int\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u586b\u5145\u95ed\u5305\u8868<\/strong><\/p>\n<p>\u8981\u586b\u5145\u95ed\u5305\u8868\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u9012\u5f52\u7b97\u6cd5\uff0c\u904d\u5386\u6811\u4e2d\u7684\u6bcf\u4e00\u4e2a\u8282\u70b9\u5e76\u63d2\u5165\u5176\u8ddd\u79bb\u5176\u6240\u6709\u7956\u5148\u7684\u8ddd\u79bb\u3002<\/p>\n<p><strong>\u67e5\u8be2\u6811\u72b6\u7ed3\u6784\u6570\u636e<\/strong><\/p>\n<p>\u8981\u67e5\u8be2\u6811\u72b6\u7ed3\u6784\u4e2d\u7684\u6240\u6709\u5305\u542b\u7279\u5b9a\u503c\u7684\u8282\u70b9\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b sql \u8bed\u53e5\uff1a<\/p>\n<pre>SELECT *\nFROM tree\nWHERE self LIKE '%&lt;value&gt;%'<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u5176\u4ed6\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n<ul>\n<li>\u5728\u5b9e\u9645\u4f7f\u7528\u4e2d\uff0c\u6211\u4eec\u5e94\u8be5\u4e3a\u6bcf\u4e2a\u5206\u7c7b\u5206\u914d\u4e00\u4e2a id\uff0c\u800c\u4e0d\u662f\u4f7f\u7528\u4e2d\u6587\u540d\u79f0\u3002<\/li>\n<li>\u95ed\u5305\u8868\u7684\u7a7a\u95f4\u5f00\u9500\u6bd4\u539f\u59cb\u6811\u72b6\u7ed3\u6784\u5927\u5c42\u7ea7\u7684\u5c42\u6570\u500d\u3002<\/li>\n<li>\u5bf9\u95ed\u5305\u8868\u8fdb\u884c\u63d2\u5165\u3001\u66f4\u65b0\u548c\u5220\u9664\u64cd\u4f5c\u9700\u8981\u989d\u5916\u7684\u5904\u7406\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 MySQL \u67e5\u8be2\u6811\u72b6\u7ed3\u6784\u6570\u636e\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\u5728 \u4e2d\u67e5\u8be2\u6811\u72b6\u7ed3\u6784\u6570\u636e \u6811\u72b6\u7ed3\u6784\u6570\u636e\u662f\u4e00\u79cd\u5e38\u89c1\u7684\u6570\u636e\u5b58\u50a8\u65b9\u5f0f\uff0c\u7528\u4e8e\u8868\u793a\u5177\u6709\u5c42\u6b21\u5173\u7cfb\u7684\u6570\u636e\u3002\u4f8b\u5982\uff0c\u6587\u4ef6\u7cfb\u7edf\u4e2d\u7684\u6587\u4ef6\u548c\u6587\u4ef6\u5939\u53ef\u4ee5\u8868\u793a\u4e3a\u4e00\u68f5\u6811\u3002 \u8981\u67e5\u8be2\u6811\u72b6\u7ed3\u6784\u6570\u636e\uff0c\u6211\u4eec\u9700\u8981\u4e00\u79cd\u65b9\u6cd5\u6765\u8868\u793a\u6811\u4e2d\u7684\u5c42\u6b21\u5173\u7cfb\u3002\u4e00\u79cd\u5e38\u89c1\u7684\u6280\u672f\u662f\u4f7f\u7528\u201c\u95ed\u5305\u8868\u201d\u3002 \u4ec0\u4e48\u662f\u95ed\u5305\u8868\uff1f \u95ed\u5305\u8868\u662f\u4e00\u4e2a\u6269\u5c55\u4e86\u6811\u72b6\u7ed3\u6784\u7684\u8868\uff0c\u5b83\u5305\u542b\u989d\u5916\u7684\u5217\u6765\u8ddf\u8e2a\u6bcf\u4e2a\u8282\u70b9\u5230\u5176\u6240\u6709\u7956\u5148\u7684\u8ddd\u79bb\u3002\u8fd9\u4f7f\u5f97\u67e5\u8be2\u6811\u4e2d\u7684\u6240\u6709\u8282\u70b9\u53d8\u5f97\u5f88\u5bb9\u6613\uff0c\u5373\u4f7f\u8fd9\u4e9b\u8282\u70b9\u5728\u67e5\u8be2\u4e2d\u6ca1\u6709\u660e\u786e\u6307\u5b9a\u3002 \u521b\u5efa\u95ed\u5305\u8868 \u8981\u521b\u5efa\u95ed\u5305\u8868\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b sql \u8bed\u53e5\uff1a create table tree( self int, parent int, distance int ); \u767b\u5f55\u540e\u590d\u5236 \u586b\u5145\u95ed\u5305\u8868 \u8981\u586b\u5145\u95ed\u5305\u8868\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4e00\u4e2a\u9012\u5f52\u7b97\u6cd5\uff0c\u904d\u5386\u6811\u4e2d\u7684\u6bcf\u4e00\u4e2a\u8282\u70b9\u5e76\u63d2\u5165\u5176\u8ddd\u79bb\u5176\u6240\u6709\u7956\u5148\u7684\u8ddd\u79bb\u3002 \u67e5\u8be2\u6811\u72b6\u7ed3\u6784\u6570\u636e \u8981\u67e5\u8be2\u6811\u72b6\u7ed3\u6784\u4e2d\u7684\u6240\u6709\u5305\u542b\u7279\u5b9a\u503c\u7684\u8282\u70b9\uff0c\u6211\u4eec\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b sql \u8bed\u53e5\uff1a SELECT * FROM tree WHERE self LIKE &#8216;%&lt;value&gt;%&#8217; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4ed6\u6ce8\u610f\u4e8b\u9879 \u5728\u5b9e\u9645\u4f7f\u7528\u4e2d\uff0c\u6211\u4eec\u5e94\u8be5\u4e3a\u6bcf\u4e2a\u5206\u7c7b\u5206\u914d\u4e00\u4e2a id\uff0c\u800c\u4e0d\u662f\u4f7f\u7528\u4e2d\u6587\u540d\u79f0\u3002 \u95ed\u5305\u8868\u7684\u7a7a\u95f4\u5f00\u9500\u6bd4\u539f\u59cb\u6811\u72b6\u7ed3\u6784\u5927\u5c42\u7ea7\u7684\u5c42\u6570\u500d\u3002 \u5bf9\u95ed\u5305\u8868\u8fdb\u884c\u63d2\u5165\u3001\u66f4\u65b0\u548c\u5220\u9664\u64cd\u4f5c\u9700\u8981\u989d\u5916\u7684\u5904\u7406\u3002 \u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 MySQL \u67e5\u8be2\u6811\u72b6\u7ed3\u6784\u6570\u636e\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},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-7115","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7115","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=7115"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7115\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7115"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}