{"id":26197,"date":"2024-11-24T09:05:15","date_gmt":"2024-11-24T01:05:15","guid":{"rendered":"https:\/\/fwq.ai\/blog\/26197\/"},"modified":"2024-11-24T09:05:15","modified_gmt":"2024-11-24T01:05:15","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-mysql-%e4%b8%ad%e6%9f%a5%e6%89%be%e5%8c%85%e5%90%ab%e7%89%b9%e5%ae%9a%e5%80%bc%e7%9a%84%e5%ad%97%e6%ae%b5%ef%bc%8c%e5%b9%b6%e6%8e%92%e9%99%a4%e4%bb%85%e5%8c%85%e5%90%ab-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/26197\/","title":{"rendered":"\u5982\u4f55\u5728 MySQL \u4e2d\u67e5\u627e\u5305\u542b\u7279\u5b9a\u503c\u7684\u5b57\u6bb5\uff0c\u5e76\u6392\u9664\u4ec5\u5305\u542b\u7279\u5b9a\u503c\u7684\u8bb0\u5f55\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173085721187127.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u5728 MySQL \u4e2d\u67e5\u627e\u5305\u542b\u7279\u5b9a\u503c\u7684\u5b57\u6bb5\uff0c\u5e76\u6392\u9664\u4ec5\u5305\u542b\u7279\u5b9a\u503c\u7684\u8bb0\u5f55\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u5728 MySQL \u4e2d\u67e5\u627e\u5305\u542b\u7279\u5b9a\u503c\u7684\u5b57\u6bb5\uff0c\u5e76\u6392\u9664\u4ec5\u5305\u542b\u7279\u5b9a\u503c\u7684\u8bb0\u5f55\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u7528  \u67e5\u627e\u5305\u542b\u7279\u5b9a\u503c\u7684\u5b57\u6bb5\uff1f<\/strong><\/p>\n<p>\u5728 mysql \u4e2d\uff0c\u8868\u4e2d\u7684\u67d0\u4e2a\u5b57\u6bb5\u503c\u53ef\u80fd\u5305\u542b\u591a\u79cd\u683c\u5f0f\uff0c\u4f8b\u5982\u7a7a\u503c\u3001\u5355\u4e00\u6570\u5b57\u6216\u4ee5\u9017\u53f7\u5206\u9694\u7684\u6570\u5b57\u5b57\u7b26\u4e32\u3002\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u8868\u540d\u4e3a &#8220;my_table&#8221;\uff0c\u5b83\u7684 &#8220;ids&#8221; \u5b57\u6bb5\u5177\u6709\u4ee5\u4e0b\u503c\uff1a<\/p>\n<pre>| ids |\n| ---- |\n| null |\n| 350 |\n| 34,35,36,37 |<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u73b0\u5728\uff0c\u6211\u4eec\u5e0c\u671b\u67e5\u8be2\u5305\u542b\u6570\u5b57 35 \u7684\u8bb0\u5f55\uff0c\u4f46\u8981\u6392\u9664\u4ec5\u5305\u542b 350 \u7684\u8bb0\u5f55\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528 mysql \u7684 find_in_set() \u51fd\u6570\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u8be5\u51fd\u6570\u68c0\u67e5\u4e00\u4e2a\u503c\u662f\u5426\u5728\u9017\u53f7\u5206\u9694\u7684\u5b57\u7b26\u4e32\u4e2d\u3002\u4ee5\u4e0b sql \u67e5\u8be2\u5c06\u68c0\u7d22\u5305\u542b 35 \u7684\u8bb0\u5f55\uff0c\u540c\u65f6\u6392\u9664\u4ec5\u5305\u542b 350 \u7684\u8bb0\u5f55\uff1a<\/p>\n<pre>select * from my_table where find_in_set(#{id}, ids)<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5728\u8fd9\u4e2a\u67e5\u8be2\u4e2d\uff0c#{id} \u662f\u8981\u641c\u7d22\u7684\u503c\uff0c\u5373 35\u3002<\/p>\n<p>\u4f7f\u7528\u6b64\u67e5\u8be2\uff0c\u5c06\u68c0\u7d22\u4ee5\u4e0b\u8bb0\u5f55\uff1a<\/p>\n<pre>| ids |\n| ---- |\n| 34,35,36,37 |<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u6210\u529f\u5730\u6392\u9664\u4e86\u4ec5\u5305\u542b 350 \u7684\u8bb0\u5f55\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5728 MySQL \u4e2d\u67e5\u627e\u5305\u542b\u7279\u5b9a\u503c\u7684\u5b57\u6bb5\uff0c\u5e76\u6392\u9664\u4ec5\u5305\u542b\u7279\u5b9a\u503c\u7684\u8bb0\u5f55\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>\u5982\u4f55\u7528 \u67e5\u627e\u5305\u542b\u7279\u5b9a\u503c\u7684\u5b57\u6bb5\uff1f \u5728 mysql \u4e2d\uff0c\u8868\u4e2d\u7684\u67d0\u4e2a\u5b57\u6bb5\u503c\u53ef\u80fd\u5305\u542b\u591a\u79cd\u683c\u5f0f\uff0c\u4f8b\u5982\u7a7a\u503c\u3001\u5355\u4e00\u6570\u5b57\u6216\u4ee5\u9017\u53f7\u5206\u9694\u7684\u6570\u5b57\u5b57\u7b26\u4e32\u3002\u5047\u8bbe\u6211\u4eec\u6709\u4e00\u4e2a\u8868\u540d\u4e3a &#8220;my_table&#8221;\uff0c\u5b83\u7684 &#8220;ids&#8221; \u5b57\u6bb5\u5177\u6709\u4ee5\u4e0b\u503c\uff1a | ids | | &#8212;- | | null | | 350 | | 34,35,36,37 | \u767b\u5f55\u540e\u590d\u5236 \u73b0\u5728\uff0c\u6211\u4eec\u5e0c\u671b\u67e5\u8be2\u5305\u542b\u6570\u5b57 35 \u7684\u8bb0\u5f55\uff0c\u4f46\u8981\u6392\u9664\u4ec5\u5305\u542b 350 \u7684\u8bb0\u5f55\u3002 \u89e3\u51b3\u65b9\u6848\uff1a \u53ef\u4ee5\u4f7f\u7528 mysql \u7684 find_in_set() \u51fd\u6570\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u8be5\u51fd\u6570\u68c0\u67e5\u4e00\u4e2a\u503c\u662f\u5426\u5728\u9017\u53f7\u5206\u9694\u7684\u5b57\u7b26\u4e32\u4e2d\u3002\u4ee5\u4e0b sql \u67e5\u8be2\u5c06\u68c0\u7d22\u5305\u542b 35 \u7684\u8bb0\u5f55\uff0c\u540c\u65f6\u6392\u9664\u4ec5\u5305\u542b 350 \u7684\u8bb0\u5f55\uff1a select * from my_table where find_in_set(#{id}, ids) \u767b\u5f55\u540e\u590d\u5236 \u5728\u8fd9\u4e2a\u67e5\u8be2\u4e2d\uff0c#{id} \u662f\u8981\u641c\u7d22\u7684\u503c\uff0c\u5373 35\u3002 \u4f7f\u7528\u6b64\u67e5\u8be2\uff0c\u5c06\u68c0\u7d22\u4ee5\u4e0b\u8bb0\u5f55\uff1a | ids [&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-26197","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26197","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=26197"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26197\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=26197"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=26197"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=26197"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}