{"id":5784,"date":"2024-11-14T08:08:50","date_gmt":"2024-11-14T00:08:50","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5784\/"},"modified":"2024-11-14T08:08:50","modified_gmt":"2024-11-14T00:08:50","slug":"mysql%e6%80%8e%e4%b9%88%e7%94%a8%e5%a4%9a%e4%b8%aa%e5%ad%97%e6%ae%b5","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5784\/","title":{"rendered":"mysql\u600e\u4e48\u7528\u591a\u4e2a\u5b57\u6bb5"},"content":{"rendered":"<blockquote><p>\n  \u5728 mysql \u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u591a\u4e2a\u5b57\u6bb5\u67e5\u8be2\u6570\u636e\uff0c\u4ee5\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u3002\u65b9\u6cd5\u5305\u62ec\uff1a1. and \u8fd0\u7b97\u7b26\uff1a\u7ec4\u5408\u591a\u4e2a\u6761\u4ef6\uff0c\u4ec5\u5f53\u6240\u6709\u6761\u4ef6\u90fd\u6ee1\u8db3\u65f6\u8fd4\u56de\u30022. or \u8fd0\u7b97\u7b26\uff1a\u7ec4\u5408\u591a\u4e2a\u6761\u4ef6\uff0c\u53ea\u8981\u6ee1\u8db3\u5176\u4e2d\u4e00\u4e2a\u6761\u4ef6\u5373\u53ef\u8fd4\u56de\u30023. in \u8fd0\u7b97\u7b26\uff1a\u68c0\u67e5\u5b57\u6bb5\u662f\u5426\u5305\u542b\u5728\u6307\u5b9a\u503c\u5217\u8868\u4e2d\u30024. between \u8fd0\u7b97\u7b26\uff1a\u68c0\u67e5\u5b57\u6bb5\u503c\u662f\u5426\u5728\u4e24\u4e2a\u6307\u5b9a\u503c\u4e4b\u95f4\u30025. \u7ec4\u5408\u8fd0\u7b97\u7b26\uff1a\u521b\u5efa\u66f4\u590d\u6742\u7684\u67e5\u8be2\uff0c\u5982\u540c\u65f6\u4f7f\u7528 and \u548c or\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/02\/2024060201242740691.jpg\" class=\"aligncenter\" title=\"mysql\u600e\u4e48\u7528\u591a\u4e2a\u5b57\u6bb5\u63d2\u56fe\" alt=\"mysql\u600e\u4e48\u7528\u591a\u4e2a\u5b57\u6bb5\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5229\u7528\u591a\u4e2a\u5b57\u6bb5\u67e5\u8be2 MySQL \u6570\u636e<\/strong><\/p>\n<p>\u5728 MySQL \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u4e2a\u5b57\u6bb5\u5bf9\u6570\u636e\u8fdb\u884c\u67e5\u8be2\uff0c\u4ee5\u8fd4\u56de\u6ee1\u8db3\u6307\u5b9a\u6761\u4ef6\u7684\u884c\u7684\u5b50\u96c6\u3002<\/p>\n<p><strong>\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p><strong>1. AND \u8fd0\u7b97\u7b26<\/strong><\/p>\n<ul>\n<li>AND \u8fd0\u7b97\u7b26\u7528\u4e8e\u7ec4\u5408\u591a\u4e2a\u6761\u4ef6\uff0c\u53ea\u6709\u6240\u6709\u6761\u4ef6\u90fd\u6ee1\u8db3\u65f6\uff0c\u624d\u4f1a\u8fd4\u56de\u884c\u3002<\/li>\n<li>\u8bed\u6cd5\uff1aWHERE field1 = value1 AND field2 = value2<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>SELECT * FROM students WHERE name = 'John' AND age = 20;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. OR \u8fd0\u7b97\u7b26<\/strong><\/p>\n<ul>\n<li>OR \u8fd0\u7b97\u7b26\u7528\u4e8e\u7ec4\u5408\u591a\u4e2a\u6761\u4ef6\uff0c\u53ea\u8981\u6ee1\u8db3\u5176\u4e2d\u4e00\u4e2a\u6761\u4ef6\uff0c\u5c31\u4f1a\u8fd4\u56de\u884c\u3002<\/li>\n<li>\u8bed\u6cd5\uff1aWHERE field1 = value1 OR field2 = value2<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>SELECT * FROM students WHERE name = 'John' OR age = 20;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. IN \u8fd0\u7b97\u7b26<\/strong><\/p>\n<ul>\n<li>IN \u8fd0\u7b97\u7b26\u7528\u4e8e\u68c0\u67e5\u4e00\u4e2a\u5b57\u6bb5\u662f\u5426\u5305\u542b\u5728\u6307\u5b9a\u503c\u5217\u8868\u4e2d\u3002<\/li>\n<li>\u8bed\u6cd5\uff1aWHERE field IN (value1, value2, &#8230;, valueN)<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>SELECT * FROM students WHERE name IN ('John', 'Alice', 'Bob');<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. BETWEEN \u8fd0\u7b97\u7b26<\/strong><\/p>\n<ul>\n<li>BETWEEN \u8fd0\u7b97\u7b26\u7528\u4e8e\u68c0\u67e5\u4e00\u4e2a\u5b57\u6bb5\u7684\u503c\u662f\u5426\u5728\u4e24\u4e2a\u6307\u5b9a\u503c\u4e4b\u95f4\u3002<\/li>\n<li>\u8bed\u6cd5\uff1aWHERE field BETWEEN value1 AND value2<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>SELECT * FROM students WHERE age BETWEEN 18 AND 25;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u7ec4\u5408\u591a\u4e2a\u8fd0\u7b97\u7b26<\/strong><\/p>\n<p>\u53ef\u4ee5\u7ec4\u5408\u591a\u4e2a\u8fd0\u7b97\u7b26\u6765\u521b\u5efa\u66f4\u590d\u6742\u7684\u67e5\u8be2\u3002\u4f8b\u5982\uff1a<\/p>\n<pre>SELECT * FROM students\nWHERE (name = 'John' OR name = 'Alice') AND age &gt; 20;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u4e2a\u67e5\u8be2\u4f1a\u8fd4\u56de\u6240\u6709\u540d\u5b57\u4e3a John \u6216 Alice \u4e14\u5e74\u9f84\u5927\u4e8e 20 \u7684\u5b66\u751f\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u7528\u591a\u4e2a\u5b57\u6bb5\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>\u5728 mysql \u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528\u591a\u4e2a\u5b57\u6bb5\u67e5\u8be2\u6570\u636e\uff0c\u4ee5\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u3002\u65b9\u6cd5\u5305\u62ec\uff1a1. and \u8fd0\u7b97\u7b26\uff1a\u7ec4\u5408\u591a\u4e2a\u6761\u4ef6\uff0c\u4ec5\u5f53\u6240\u6709\u6761\u4ef6\u90fd\u6ee1\u8db3\u65f6\u8fd4\u56de\u30022. or \u8fd0\u7b97\u7b26\uff1a\u7ec4\u5408\u591a\u4e2a\u6761\u4ef6\uff0c\u53ea\u8981\u6ee1\u8db3\u5176\u4e2d\u4e00\u4e2a\u6761\u4ef6\u5373\u53ef\u8fd4\u56de\u30023. in \u8fd0\u7b97\u7b26\uff1a\u68c0\u67e5\u5b57\u6bb5\u662f\u5426\u5305\u542b\u5728\u6307\u5b9a\u503c\u5217\u8868\u4e2d\u30024. between \u8fd0\u7b97\u7b26\uff1a\u68c0\u67e5\u5b57\u6bb5\u503c\u662f\u5426\u5728\u4e24\u4e2a\u6307\u5b9a\u503c\u4e4b\u95f4\u30025. \u7ec4\u5408\u8fd0\u7b97\u7b26\uff1a\u521b\u5efa\u66f4\u590d\u6742\u7684\u67e5\u8be2\uff0c\u5982\u540c\u65f6\u4f7f\u7528 and \u548c or\u3002 \u5229\u7528\u591a\u4e2a\u5b57\u6bb5\u67e5\u8be2 MySQL \u6570\u636e \u5728 MySQL \u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u4e2a\u5b57\u6bb5\u5bf9\u6570\u636e\u8fdb\u884c\u67e5\u8be2\uff0c\u4ee5\u8fd4\u56de\u6ee1\u8db3\u6307\u5b9a\u6761\u4ef6\u7684\u884c\u7684\u5b50\u96c6\u3002 \u65b9\u6cd5\uff1a 1. AND \u8fd0\u7b97\u7b26 AND \u8fd0\u7b97\u7b26\u7528\u4e8e\u7ec4\u5408\u591a\u4e2a\u6761\u4ef6\uff0c\u53ea\u6709\u6240\u6709\u6761\u4ef6\u90fd\u6ee1\u8db3\u65f6\uff0c\u624d\u4f1a\u8fd4\u56de\u884c\u3002 \u8bed\u6cd5\uff1aWHERE field1 = value1 AND field2 = value2 \u793a\u4f8b\uff1a SELECT * FROM students WHERE name = &#8216;John&#8217; AND age = 20; \u767b\u5f55\u540e\u590d\u5236 2. OR \u8fd0\u7b97\u7b26 OR \u8fd0\u7b97\u7b26\u7528\u4e8e\u7ec4\u5408\u591a\u4e2a\u6761\u4ef6\uff0c\u53ea\u8981\u6ee1\u8db3\u5176\u4e2d\u4e00\u4e2a\u6761\u4ef6\uff0c\u5c31\u4f1a\u8fd4\u56de\u884c\u3002 \u8bed\u6cd5\uff1aWHERE [&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-5784","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5784","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=5784"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5784\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5784"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5784"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5784"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}