{"id":6258,"date":"2024-11-14T09:29:12","date_gmt":"2024-11-14T01:29:12","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6258\/"},"modified":"2024-11-14T09:29:12","modified_gmt":"2024-11-14T01:29:12","slug":"%e6%80%8e%e6%a0%b7%e5%b0%86%e6%95%b0%e7%bb%84%e4%bd%9c%e4%b8%basql%e4%b8%adin%e7%9a%84%e6%9f%a5%e8%af%a2%e6%9d%a1%e4%bb%b6","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6258\/","title":{"rendered":"\u600e\u6837\u5c06\u6570\u7ec4\u4f5c\u4e3asql\u4e2din\u7684\u67e5\u8be2\u6761\u4ef6"},"content":{"rendered":"<blockquote><p>\n  sql \u4e2d\u4f7f\u7528\u6570\u7ec4\u4f5c\u4e3a in \u67e5\u8be2\u6761\u4ef6\u7684\u65b9\u6cd5\uff1a1. \u521b\u5efa\u6570\u7ec4\u53d8\u91cf\uff1a\u4f7f\u7528 create array \u8bed\u53e5\u521b\u5efa\u6570\u7ec4\u53d8\u91cf\uff0c\u5305\u542b\u6240\u9700\u503c\u30022. \u5728 in \u67e5\u8be2\u4e2d\u4f7f\u7528\u6570\u7ec4\u53d8\u91cf\uff1a\u5728 in \u67e5\u8be2\u4e2d\uff0c\u4f7f\u7528\u6570\u7ec4\u53d8\u91cf\u4f5c\u4e3a\u503c\u5217\u8868\uff0c\u68c0\u67e5\u5217\u503c\u662f\u5426\u5305\u542b\u5728\u6570\u7ec4\u4e2d\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/17\/2024061710362094527.jpg\" class=\"aligncenter\" title=\"\u600e\u6837\u5c06\u6570\u7ec4\u4f5c\u4e3asql\u4e2din\u7684\u67e5\u8be2\u6761\u4ef6\u63d2\u56fe\" alt=\"\u600e\u6837\u5c06\u6570\u7ec4\u4f5c\u4e3asql\u4e2din\u7684\u67e5\u8be2\u6761\u4ef6\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5c06\u6570\u7ec4\u4f5c\u4e3a SQL \u4e2d IN \u67e5\u8be2\u7684\u6761\u4ef6<\/strong><\/p>\n<p>\u5728 SQL \u4e2d\uff0cIN \u8fd0\u7b97\u7b26\u7528\u4e8e\u68c0\u67e5\u4e00\u4e2a\u503c\u662f\u5426\u5305\u542b\u5728\u4e00\u4e2a\u503c\u5217\u8868\u4e2d\u3002\u901a\u5e38\uff0c\u6b64\u5217\u8868\u662f\u4ee5\u9017\u53f7\u5206\u9694\u7684\u503c\u5217\u8868\u7684\u5f62\u5f0f\u63d0\u4f9b\u3002\u4f46\u662f\uff0c\u60a8\u4e5f\u53ef\u4ee5\u4f7f\u7528\u6570\u7ec4\u4f5c\u4e3a IN \u5217\u8868\u3002<\/p>\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n<ol>\n<li> <strong>\u521b\u5efa\u6570\u7ec4\u53d8\u91cf\uff1a<\/strong>\u4f7f\u7528 CREATE ARRAY \u8bed\u53e5\u521b\u5efa\u4e00\u4e2a\u6570\u7ec4\u53d8\u91cf\u6765\u5b58\u50a8\u60a8\u7684\u503c\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/li>\n<\/ol>\n<pre>CREATE ARRAY array_name AS ARRAY[&lt;type&gt;] OF &lt;value1&gt;, &lt;value2&gt;, ...;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4f8b\u5982\uff0c\u8981\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a my_array \u7684\u6574\u578b\u6570\u7ec4\u5e76\u5305\u542b\u503c 1\u30012 \u548c 3\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\uff1a<\/p>\n<pre>CREATE ARRAY my_array AS ARRAY[INTEGER] OF 1, 2, 3;<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<ol>\n<li> <strong>\u5728 IN \u67e5\u8be2\u4e2d\u4f7f\u7528\u6570\u7ec4\u53d8\u91cf\uff1a<\/strong>\u5728 IN \u67e5\u8be2\u4e2d\u4f7f\u7528 array_name \u53d8\u91cf\u4f5c\u4e3a\u503c\u5217\u8868\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/li>\n<\/ol>\n<pre>SELECT * FROM table_name WHERE column_name IN (array_name);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4f8b\u5982\uff0c\u8981\u9009\u62e9\u5305\u542b my_array \u4e2d\u503c\u7684 column_name \u5217\u503c\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8be2\uff1a<\/p>\n<pre>SELECT * FROM table_name WHERE column_name IN (my_array);<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd\u6570\u7ec4\u53d8\u91cf\u4e0e\u8981\u67e5\u8be2\u7684\u5217\u5177\u6709\u76f8\u540c\u7684\u6570\u636e\u7c7b\u578b\u3002<\/li>\n<li>IN \u67e5\u8be2\u4e2d\u7684\u6570\u7ec4\u53d8\u91cf\u5fc5\u987b\u662f\u5355\u7ef4\u6570\u7ec4\u3002<\/li>\n<li>\u5982\u679c\u6570\u7ec4\u53d8\u91cf\u4e3a\u7a7a\uff0c\u5219 IN \u67e5\u8be2\u5c06\u8fd4\u56de\u7a7a\u7ed3\u679c\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u6837\u5c06\u6570\u7ec4\u4f5c\u4e3asql\u4e2din\u7684\u67e5\u8be2\u6761\u4ef6\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>sql \u4e2d\u4f7f\u7528\u6570\u7ec4\u4f5c\u4e3a in \u67e5\u8be2\u6761\u4ef6\u7684\u65b9\u6cd5\uff1a1. \u521b\u5efa\u6570\u7ec4\u53d8\u91cf\uff1a\u4f7f\u7528 create array \u8bed\u53e5\u521b\u5efa\u6570\u7ec4\u53d8\u91cf\uff0c\u5305\u542b\u6240\u9700\u503c\u30022. \u5728 in \u67e5\u8be2\u4e2d\u4f7f\u7528\u6570\u7ec4\u53d8\u91cf\uff1a\u5728 in \u67e5\u8be2\u4e2d\uff0c\u4f7f\u7528\u6570\u7ec4\u53d8\u91cf\u4f5c\u4e3a\u503c\u5217\u8868\uff0c\u68c0\u67e5\u5217\u503c\u662f\u5426\u5305\u542b\u5728\u6570\u7ec4\u4e2d\u3002 \u5982\u4f55\u5c06\u6570\u7ec4\u4f5c\u4e3a SQL \u4e2d IN \u67e5\u8be2\u7684\u6761\u4ef6 \u5728 SQL \u4e2d\uff0cIN \u8fd0\u7b97\u7b26\u7528\u4e8e\u68c0\u67e5\u4e00\u4e2a\u503c\u662f\u5426\u5305\u542b\u5728\u4e00\u4e2a\u503c\u5217\u8868\u4e2d\u3002\u901a\u5e38\uff0c\u6b64\u5217\u8868\u662f\u4ee5\u9017\u53f7\u5206\u9694\u7684\u503c\u5217\u8868\u7684\u5f62\u5f0f\u63d0\u4f9b\u3002\u4f46\u662f\uff0c\u60a8\u4e5f\u53ef\u4ee5\u4f7f\u7528\u6570\u7ec4\u4f5c\u4e3a IN \u5217\u8868\u3002 \u6b65\u9aa4\uff1a \u521b\u5efa\u6570\u7ec4\u53d8\u91cf\uff1a\u4f7f\u7528 CREATE ARRAY \u8bed\u53e5\u521b\u5efa\u4e00\u4e2a\u6570\u7ec4\u53d8\u91cf\u6765\u5b58\u50a8\u60a8\u7684\u503c\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a CREATE ARRAY array_name AS ARRAY[&lt;type&gt;] OF &lt;value1&gt;, &lt;value2&gt;, &#8230;; \u767b\u5f55\u540e\u590d\u5236 \u4f8b\u5982\uff0c\u8981\u521b\u5efa\u4e00\u4e2a\u540d\u4e3a my_array \u7684\u6574\u578b\u6570\u7ec4\u5e76\u5305\u542b\u503c 1\u30012 \u548c 3\uff0c\u8bf7\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\uff1a CREATE ARRAY my_array AS ARRAY[INTEGER] OF 1, 2, 3; \u767b\u5f55\u540e\u590d\u5236 [&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-6258","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6258","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=6258"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6258\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6258"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6258"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6258"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}