{"id":7635,"date":"2024-11-14T15:23:16","date_gmt":"2024-11-14T07:23:16","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7635\/"},"modified":"2024-11-14T15:23:16","modified_gmt":"2024-11-14T07:23:16","slug":"mysql-%e4%b8%ad%e5%a6%82%e4%bd%95%e4%bb%8e%e9%80%97%e5%8f%b7%e5%88%86%e9%9a%94%e7%9a%84%e5%ad%97%e6%ae%b5%e6%8f%90%e5%8f%96%e5%a4%9a%e4%b8%aa%e5%80%bc%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7635\/","title":{"rendered":"MySQL \u4e2d\u5982\u4f55\u4ece\u9017\u53f7\u5206\u9694\u7684\u5b57\u6bb5\u63d0\u53d6\u591a\u4e2a\u503c\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173106991891898.jpg\" class=\"aligncenter\" title=\"MySQL \u4e2d\u5982\u4f55\u4ece\u9017\u53f7\u5206\u9694\u7684\u5b57\u6bb5\u63d0\u53d6\u591a\u4e2a\u503c\uff1f\u63d2\u56fe\" alt=\"MySQL \u4e2d\u5982\u4f55\u4ece\u9017\u53f7\u5206\u9694\u7684\u5b57\u6bb5\u63d0\u53d6\u591a\u4e2a\u503c\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u4ece\u9017\u53f7\u5206\u9694\u5b57\u6bb5\u63d0\u53d6\u591a\u4e2a\u503c<\/strong><\/p>\n<p>\u5982\u4f55\u5728  \u4e2d\u4ece\u5b58\u50a8\u4e3a\u9017\u53f7\u5206\u9694\u503c\uff08\u4f8b\u5982\u201c1\uff0c2\uff0c3\uff0c4\uff0c5\uff0c6\u201d\uff09\u7684\u5b57\u6bb5\u4e2d\u5206\u522b\u63d0\u53d6\u8fd9\u4e9b\u503c\uff1f<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528 mysql \u5185\u7f6e\u51fd\u6570 substring_index() \u5c06\u9017\u53f7\u5206\u9694\u7684\u503c\u8f6c\u6362\u4e3a\u591a\u884c\uff0c\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\u5c06\u9017\u53f7\u5206\u9694\u7684\u503c\u4f5c\u4e3a\u7b2c\u4e00\u4e2a\u53c2\u6570\u4f20\u9012\u7ed9 substring_index() \u51fd\u6570\u3002<\/li>\n<li>\u5c06\u9017\u53f7\u4f5c\u4e3a\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4f20\u9012\uff0c\u8868\u793a\u5206\u9694\u7b26\u3002<\/li>\n<li>\u5c06 1 \u4f5c\u4e3a\u7b2c\u4e09\u4e2a\u53c2\u6570\uff0c\u6307\u793a\u8981\u63d0\u53d6\u7b2c\u4e00\u4e2a\u503c\u3002<\/li>\n<\/ol>\n<p>\u4f8b\u5982\uff0c\u4ee5\u4e0b\u67e5\u8be2\u5c06\u4ece\u9017\u53f7\u5206\u9694\u7684\u5b57\u6bb5\u4e2d\u63d0\u53d6\u524d\u4e09\u4e2a\u503c\uff1a<\/p>\n<pre>select substring_index('1,2,3,4,5,6', ',', 1) as val\nunion all select substring_index(substring_index('1,2,3,4,5,6', ',', 2), ',', -1)\nunion all select substring_index(substring_index('1,2,3,4,5,6', ',', 3), ',', -1)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5b9e\u9645\u6d4b\u8bd5\u7ed3\u679c\u5982\u4e0b\uff1a<\/p>\n<pre>+------+\n| val  |\n+------+\n| 1    |\n| 2    |\n| 3    |\n+------+<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fMySQL \u4e2d\u5982\u4f55\u4ece\u9017\u53f7\u5206\u9694\u7684\u5b57\u6bb5\u63d0\u53d6\u591a\u4e2a\u503c\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>\u4ece\u9017\u53f7\u5206\u9694\u5b57\u6bb5\u63d0\u53d6\u591a\u4e2a\u503c \u5982\u4f55\u5728 \u4e2d\u4ece\u5b58\u50a8\u4e3a\u9017\u53f7\u5206\u9694\u503c\uff08\u4f8b\u5982\u201c1\uff0c2\uff0c3\uff0c4\uff0c5\uff0c6\u201d\uff09\u7684\u5b57\u6bb5\u4e2d\u5206\u522b\u63d0\u53d6\u8fd9\u4e9b\u503c\uff1f \u89e3\u51b3\u65b9\u6848 \u53ef\u4ee5\u4f7f\u7528 mysql \u5185\u7f6e\u51fd\u6570 substring_index() \u5c06\u9017\u53f7\u5206\u9694\u7684\u503c\u8f6c\u6362\u4e3a\u591a\u884c\uff0c\u5177\u4f53\u6b65\u9aa4\u5982\u4e0b\uff1a \u5c06\u9017\u53f7\u5206\u9694\u7684\u503c\u4f5c\u4e3a\u7b2c\u4e00\u4e2a\u53c2\u6570\u4f20\u9012\u7ed9 substring_index() \u51fd\u6570\u3002 \u5c06\u9017\u53f7\u4f5c\u4e3a\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4f20\u9012\uff0c\u8868\u793a\u5206\u9694\u7b26\u3002 \u5c06 1 \u4f5c\u4e3a\u7b2c\u4e09\u4e2a\u53c2\u6570\uff0c\u6307\u793a\u8981\u63d0\u53d6\u7b2c\u4e00\u4e2a\u503c\u3002 \u4f8b\u5982\uff0c\u4ee5\u4e0b\u67e5\u8be2\u5c06\u4ece\u9017\u53f7\u5206\u9694\u7684\u5b57\u6bb5\u4e2d\u63d0\u53d6\u524d\u4e09\u4e2a\u503c\uff1a select substring_index(&#8216;1,2,3,4,5,6&#8217;, &#8216;,&#8217;, 1) as val union all select substring_index(substring_index(&#8216;1,2,3,4,5,6&#8217;, &#8216;,&#8217;, 2), &#8216;,&#8217;, -1) union all select substring_index(substring_index(&#8216;1,2,3,4,5,6&#8217;, &#8216;,&#8217;, 3), &#8216;,&#8217;, -1) \u767b\u5f55\u540e\u590d\u5236 \u5b9e\u9645\u6d4b\u8bd5\u7ed3\u679c\u5982\u4e0b\uff1a +&#8212;&#8212;+ | val | +&#8212;&#8212;+ | 1 | | 2 | | 3 | [&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-7635","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7635","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=7635"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7635\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7635"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7635"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7635"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}