{"id":7725,"date":"2024-11-14T16:55:45","date_gmt":"2024-11-14T08:55:45","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7725\/"},"modified":"2024-11-14T16:55:45","modified_gmt":"2024-11-14T08:55:45","slug":"%e5%a6%82%e4%bd%95%e5%b0%86mysql%e5%ad%97%e6%ae%b5%e4%b8%ad%e7%9a%84%e9%80%97%e5%8f%b7%e5%88%86%e9%9a%94%e5%80%bc%e8%bd%ac%e6%8d%a2%e4%b8%ba%e5%a4%9a%e8%a1%8c%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7725\/","title":{"rendered":"\u5982\u4f55\u5c06MySQL\u5b57\u6bb5\u4e2d\u7684\u9017\u53f7\u5206\u9694\u503c\u8f6c\u6362\u4e3a\u591a\u884c\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173120023371338.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5c06MySQL\u5b57\u6bb5\u4e2d\u7684\u9017\u53f7\u5206\u9694\u503c\u8f6c\u6362\u4e3a\u591a\u884c\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5c06MySQL\u5b57\u6bb5\u4e2d\u7684\u9017\u53f7\u5206\u9694\u503c\u8f6c\u6362\u4e3a\u591a\u884c\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5206\u79bb\u9017\u53f7\u5206\u9694\u5b57\u6bb5\u7684\u503c<\/strong><\/p>\n<p>\u5047\u8bbe\u60a8\u6709\u4e00\u4e2a\u5b57\u6bb5\u5305\u542b\u4e00\u4e2a\u4ee5\u9017\u53f7\u5206\u9694\u7684\u503c\u5217\u8868\uff0c\u4f8b\u5982\u201c1\uff0c2\uff0c3\uff0c4\uff0c5\uff0c6\u201d\u3002\u8981\u5206\u522b\u63d0\u53d6\u8fd9\u4e9b\u503c\uff0c\u8bf7\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p><strong>\u4f7f\u7528 substring_index() \u51fd\u6570<\/strong><\/p>\n<p>mysql\u63d0\u4f9b\u4e86 substring_index() \u51fd\u6570\uff0c\u5b83\u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u5b50\u5b57\u7b26\u4e32\u63d0\u53d6\u5230\u6307\u5b9a\u7684\u5206\u9694\u7b26\u3002<\/p>\n<p><strong>\u5c06\u9017\u53f7\u5206\u9694\u7684\u503c\u8f6c\u6362\u4e3a\u591a\u884c<\/strong><\/p>\n<p>\u4f7f\u7528 substring_index() \u5c06\u9017\u53f7\u5206\u9694\u7684\u503c\u62c6\u5206\u4e3a\u591a\u884c\uff0c\u5206\u9694\u5b57\u7b26\u4e3a\u9017\u53f7\u3002<\/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>\u6b64\u67e5\u8be2\u5c06\u8fd4\u56de\u4ee5\u4e0b\u7ed3\u679c\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>\u91cd\u590d union all \u8bed\u53e5\u4ee5\u63d0\u53d6\u6240\u9700\u7684\u6240\u6709\u503c\u3002<\/p>\n<p><strong>\u5b9e\u9645\u6d4b\u8bd5<\/strong><\/p>\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8be2\u6765\u6d4b\u8bd5\u6b64\u65b9\u6cd5\uff1a<\/p>\n<pre>mysql&gt; SELECT SUBSTRING_INDEX('1,2,3,4,5,6', ',', 1) AS val\n    -&gt; UNION ALL SELECT SUBSTRING_INDEX(SUBSTRING_INDEX('1,2,3,4,5,6', ',', 2), ',', -1)\n    -&gt; UNION ALL SELECT SUBSTRING_INDEX(SUBSTRING_INDEX('1,2,3,4,5,6', ',', 3), ',', -1)\n    -&gt; ;\n+------+\n| val  |\n+------+\n| 1    |\n| 2    |\n| 3    |\n+------+\n3 rows in set (0.00 sec)\n\nmysql&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5c06MySQL\u5b57\u6bb5\u4e2d\u7684\u9017\u53f7\u5206\u9694\u503c\u8f6c\u6362\u4e3a\u591a\u884c\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>\u5206\u79bb\u9017\u53f7\u5206\u9694\u5b57\u6bb5\u7684\u503c \u5047\u8bbe\u60a8\u6709\u4e00\u4e2a\u5b57\u6bb5\u5305\u542b\u4e00\u4e2a\u4ee5\u9017\u53f7\u5206\u9694\u7684\u503c\u5217\u8868\uff0c\u4f8b\u5982\u201c1\uff0c2\uff0c3\uff0c4\uff0c5\uff0c6\u201d\u3002\u8981\u5206\u522b\u63d0\u53d6\u8fd9\u4e9b\u503c\uff0c\u8bf7\u9075\u5faa\u4ee5\u4e0b\u6b65\u9aa4\uff1a \u4f7f\u7528 substring_index() \u51fd\u6570 mysql\u63d0\u4f9b\u4e86 substring_index() \u51fd\u6570\uff0c\u5b83\u53ef\u4ee5\u5c06\u5b57\u7b26\u4e32\u4e2d\u7684\u5b50\u5b57\u7b26\u4e32\u63d0\u53d6\u5230\u6307\u5b9a\u7684\u5206\u9694\u7b26\u3002 \u5c06\u9017\u53f7\u5206\u9694\u7684\u503c\u8f6c\u6362\u4e3a\u591a\u884c \u4f7f\u7528 substring_index() \u5c06\u9017\u53f7\u5206\u9694\u7684\u503c\u62c6\u5206\u4e3a\u591a\u884c\uff0c\u5206\u9694\u5b57\u7b26\u4e3a\u9017\u53f7\u3002 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 \u6b64\u67e5\u8be2\u5c06\u8fd4\u56de\u4ee5\u4e0b\u7ed3\u679c\uff1a +&#8212;&#8212;+ | val | +&#8212;&#8212;+ | 1 | | 2 | | 3 | +&#8212;&#8212;+ \u767b\u5f55\u540e\u590d\u5236 \u91cd\u590d union all [&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-7725","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7725","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=7725"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7725\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7725"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7725"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7725"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}