{"id":26269,"date":"2024-11-24T09:53:31","date_gmt":"2024-11-24T01:53:31","guid":{"rendered":"https:\/\/fwq.ai\/blog\/26269\/"},"modified":"2024-11-24T09:53:31","modified_gmt":"2024-11-24T01:53:31","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-mysql-%e6%9f%a5%e8%af%a2%e5%8c%85%e5%90%ab%e7%89%b9%e5%ae%9a%e6%95%b0%e5%ad%97%e4%b8%94%e4%b8%8d%e5%8f%aa%e5%8c%85%e5%90%ab%e8%af%a5%e6%95%b0%e5%ad%97%e7%9a%84-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/26269\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 MySQL \u67e5\u8be2\u5305\u542b\u7279\u5b9a\u6570\u5b57\u4e14\u4e0d\u53ea\u5305\u542b\u8be5\u6570\u5b57\u7684\u8bb0\u5f55\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173087259930170.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 MySQL \u67e5\u8be2\u5305\u542b\u7279\u5b9a\u6570\u5b57\u4e14\u4e0d\u53ea\u5305\u542b\u8be5\u6570\u5b57\u7684\u8bb0\u5f55\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 MySQL \u67e5\u8be2\u5305\u542b\u7279\u5b9a\u6570\u5b57\u4e14\u4e0d\u53ea\u5305\u542b\u8be5\u6570\u5b57\u7684\u8bb0\u5f55\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong> \u67e5\u627e\u5b57\u6bb5\u5305\u542b\u7279\u5b9a\u503c\u7684\u67e5\u8be2<\/strong><\/p>\n<p>\u8868\u4e2d\u5b58\u5728\u4e00\u4e2a\u5b57\u6bb5 ids\uff0c\u5176\u503c\u53ef\u80fd\u4e3a\u7a7a\u3001\u5355\u4e00\u6570\u5b57\u6216\u4ee5\u9017\u53f7\u5206\u9694\u7684\u7eaf\u6570\u5b57\u5b57\u7b26\u4e32\u3002\u7528\u6237\u5e0c\u671b\u67e5\u8be2\u51fa\u5305\u542b\u7279\u5b9a\u6570\u5b57\uff08\u4f8b\u5982 35\uff09\u7684\u8bb0\u5f55\uff0c\u6392\u9664\u4ec5\u5305\u542b\u8be5\u6570\u5b57\u4f5c\u4e3a\u5355\u72ec\u503c\u7684\u8bb0\u5f55\u3002<\/p>\n<p><strong>mysql \u67e5\u8be2\u89e3\u7b54<\/strong><\/p>\n<p>\u4f7f\u7528 find_in_set() \u51fd\u6570\u53ef\u4ee5\u5b9e\u73b0\u6b64\u67e5\u8be2\u3002\u8be5\u51fd\u6570\u5c06\u6307\u5b9a\u5b57\u7b26\u4e32\uff08#{id}\uff09\u4f5c\u4e3a\u53c2\u6570\uff0c\u5e76\u641c\u7d22\u662f\u5426\u5728\u5b57\u6bb5 ids \u4e2d\u627e\u5230\u8be5\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u4e0b\u9762\u7684\u67e5\u8be2\u5c06\u8fd4\u56de\u5305\u542b\u6570\u5b57 35 \u7684\u8bb0\u5f55\uff1a<\/p>\n<pre>select *\nfrom \u8868\u540d\nwhere find_in_set(#{id}, ids) &gt; 0;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4f8b\u5982\uff0c\u8981\u67e5\u627e\u5305\u542b\u6570\u5b57 35 \u7684\u8bb0\u5f55\uff0c\u67e5\u8be2\u5e94\u4e3a\uff1a<\/p>\n<pre>SELECT *\nFROM \u8868\u540d\nWHERE FIND_IN_SET(35, ids) &gt; 0;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u4e2a\u67e5\u8be2\u5c06\u8fd4\u56de ids \u5b57\u6bb5\u503c\u4e3a &#8220;34,35,36,37&#8221; \u7684\u8bb0\u5f55\uff0c\u56e0\u4e3a\u5b83\u5305\u542b\u6570\u5b57 35\uff0c\u800c\u6392\u9664 ids \u5b57\u6bb5\u503c\u4e3a 350 \u7684\u8bb0\u5f55\uff0c\u56e0\u4e3a\u8be5\u503c\u4e0d\u5305\u542b\u6570\u5b57 35\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 MySQL \u67e5\u8be2\u5305\u542b\u7279\u5b9a\u6570\u5b57\u4e14\u4e0d\u53ea\u5305\u542b\u8be5\u6570\u5b57\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>\u67e5\u627e\u5b57\u6bb5\u5305\u542b\u7279\u5b9a\u503c\u7684\u67e5\u8be2 \u8868\u4e2d\u5b58\u5728\u4e00\u4e2a\u5b57\u6bb5 ids\uff0c\u5176\u503c\u53ef\u80fd\u4e3a\u7a7a\u3001\u5355\u4e00\u6570\u5b57\u6216\u4ee5\u9017\u53f7\u5206\u9694\u7684\u7eaf\u6570\u5b57\u5b57\u7b26\u4e32\u3002\u7528\u6237\u5e0c\u671b\u67e5\u8be2\u51fa\u5305\u542b\u7279\u5b9a\u6570\u5b57\uff08\u4f8b\u5982 35\uff09\u7684\u8bb0\u5f55\uff0c\u6392\u9664\u4ec5\u5305\u542b\u8be5\u6570\u5b57\u4f5c\u4e3a\u5355\u72ec\u503c\u7684\u8bb0\u5f55\u3002 mysql \u67e5\u8be2\u89e3\u7b54 \u4f7f\u7528 find_in_set() \u51fd\u6570\u53ef\u4ee5\u5b9e\u73b0\u6b64\u67e5\u8be2\u3002\u8be5\u51fd\u6570\u5c06\u6307\u5b9a\u5b57\u7b26\u4e32\uff08#{id}\uff09\u4f5c\u4e3a\u53c2\u6570\uff0c\u5e76\u641c\u7d22\u662f\u5426\u5728\u5b57\u6bb5 ids \u4e2d\u627e\u5230\u8be5\u5b57\u7b26\u4e32\u3002 \u4e0b\u9762\u7684\u67e5\u8be2\u5c06\u8fd4\u56de\u5305\u542b\u6570\u5b57 35 \u7684\u8bb0\u5f55\uff1a select * from \u8868\u540d where find_in_set(#{id}, ids) &gt; 0; \u767b\u5f55\u540e\u590d\u5236 \u4f8b\u5982\uff0c\u8981\u67e5\u627e\u5305\u542b\u6570\u5b57 35 \u7684\u8bb0\u5f55\uff0c\u67e5\u8be2\u5e94\u4e3a\uff1a SELECT * FROM \u8868\u540d WHERE FIND_IN_SET(35, ids) &gt; 0; \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u4e2a\u67e5\u8be2\u5c06\u8fd4\u56de ids \u5b57\u6bb5\u503c\u4e3a &#8220;34,35,36,37&#8221; \u7684\u8bb0\u5f55\uff0c\u56e0\u4e3a\u5b83\u5305\u542b\u6570\u5b57 35\uff0c\u800c\u6392\u9664 ids \u5b57\u6bb5\u503c\u4e3a 350 \u7684\u8bb0\u5f55\uff0c\u56e0\u4e3a\u8be5\u503c\u4e0d\u5305\u542b\u6570\u5b57 35\u3002 \u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 MySQL \u67e5\u8be2\u5305\u542b\u7279\u5b9a\u6570\u5b57\u4e14\u4e0d\u53ea\u5305\u542b\u8be5\u6570\u5b57\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},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-26269","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26269","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=26269"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/26269\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=26269"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=26269"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=26269"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}