{"id":6891,"date":"2024-11-14T13:29:57","date_gmt":"2024-11-14T05:29:57","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6891\/"},"modified":"2024-11-14T13:29:57","modified_gmt":"2024-11-14T05:29:57","slug":"mysql-%e8%81%94%e5%90%88%e7%b4%a2%e5%bc%95%e7%9a%84%e6%9c%80%e5%b7%a6%e5%89%8d%e7%bc%80%e5%8e%9f%e5%88%99%ef%bc%9a%e4%b8%ba%e4%bd%95%e6%9f%a5%e8%af%a2%e6%9d%a1%e4%bb%b6%e5%bf%85%e9%a1%bb%e5%8c%85","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6891\/","title":{"rendered":"MySQL \u8054\u5408\u7d22\u5f15\u7684\u6700\u5de6\u524d\u7f00\u539f\u5219\uff1a\u4e3a\u4f55\u67e5\u8be2\u6761\u4ef6\u5fc5\u987b\u5305\u542b\u6700\u5de6\u4fa7\u5b57\u6bb5\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173002339299329.jpg\" class=\"aligncenter\" title=\"MySQL \u8054\u5408\u7d22\u5f15\u7684\u6700\u5de6\u524d\u7f00\u539f\u5219\uff1a\u4e3a\u4f55\u67e5\u8be2\u6761\u4ef6\u5fc5\u987b\u5305\u542b\u6700\u5de6\u4fa7\u5b57\u6bb5\uff1f\u63d2\u56fe\" alt=\"MySQL \u8054\u5408\u7d22\u5f15\u7684\u6700\u5de6\u524d\u7f00\u539f\u5219\uff1a\u4e3a\u4f55\u67e5\u8be2\u6761\u4ef6\u5fc5\u987b\u5305\u542b\u6700\u5de6\u4fa7\u5b57\u6bb5\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong> \u4e3a\u4f55\u9700\u8981\u6700\u5de6\u524d\u7f00\u8981\u6c42<\/strong><\/p>\n<p>\u5728\u4f18\u5316 mysql \u67e5\u8be2\u65f6\uff0c\u6700\u5de6\u524d\u7f00\u539f\u5219\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002\u5f53\u4f7f\u7528\u8054\u5408\u7d22\u5f15\u65f6\uff0c\u53ea\u6709\u6ee1\u8db3\u6700\u5de6\u524d\u7f00\u6761\u4ef6\u7684\u67e5\u8be2\u624d\u80fd\u5229\u7528\u7d22\u5f15\u3002<\/p>\n<p><strong>\u4ec0\u4e48\u662f\u6700\u5de6\u524d\u7f00\u539f\u5219<\/strong><\/p>\n<p>\u6700\u5de6\u524d\u7f00\u539f\u5219\u89c4\u5b9a\uff0c\u8054\u5408\u7d22\u5f15\u4e2d\u7684\u5de6\u7aef\u5b57\u6bb5\u5fc5\u987b\u53c2\u4e0e\u67e5\u8be2\u6761\u4ef6\u7684\u6bd4\u8f83\u3002\u4f8b\u5982\uff0c\u5bf9\u4e8e\u7d22\u5f15 (user_id, created_at)\uff0c\u4ee5\u4e0b\u67e5\u8be2\u53ef\u4ee5\u5229\u7528\u7d22\u5f15\uff1a<\/p>\n<pre>select * from tweet where created_at &lt; '2021-11-11' and user_id = 1;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u4f18\u5316\u5668\u65e0\u6cd5\u4f18\u5316\u987a\u5e8f\u8c03\u6574<\/strong><\/p>\n<p>\u60a8\u63d0\u5230\u7684\u4f18\u5316\u5668\u65e0\u6cd5\u5c06\u4e0a\u8ff0\u67e5\u8be2\u4f18\u5316\u4e3a\u4ee5\u4e0b\u987a\u5e8f\uff1a<\/p>\n<pre>SELECT * FROM tweet WHERE user_id = 1 AND created_at &lt; '2021-11-11';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8fd9\u662f\u56e0\u4e3a\u6700\u5de6\u524d\u7f00\u539f\u5219\u9700\u8981\u5de6\u7aef\u7684\u5b57\u6bb5 user_id \u53c2\u4e0e\u67e5\u8be2\u6761\u4ef6\u7684\u6bd4\u8f83\u3002\u8df3\u8fc7 user_id \u5c06\u5bfc\u81f4\u7d22\u5f15\u65e0\u6cd5\u4f7f\u7528\u3002<\/p>\n<p><strong>\u5de6\u524d\u7f00\u793a\u4f8b<\/strong><\/p>\n<p>\u4e3a\u4e86\u8fdb\u4e00\u6b65\u7406\u89e3\u6700\u5de6\u524d\u7f00\u539f\u5219\uff0c\u8bf7\u8003\u8651\u4ee5\u4e0b\u793a\u4f8b\uff1a<\/p>\n<ul>\n<li>\u7d22\u5f15 (a, b, c)<\/li>\n<li>\u67e5\u8be2\u6761\u4ef6\uff1aa = 1<\/li>\n<\/ul>\n<p><strong>\u6b64\u5904\u53ef\u4f7f\u7528\u7d22\u5f15<\/strong><\/p>\n<p>\u56e0\u4e3a\u5de6\u7aef\u5b57\u6bb5 a \u53c2\u4e0e\u4e86\u67e5\u8be2\u6761\u4ef6\u7684\u6bd4\u8f83\u3002<\/p>\n<ul>\n<li>\u67e5\u8be2\u6761\u4ef6\uff1ac = 1<\/li>\n<\/ul>\n<p><strong>\u6b64\u5904\u4e0d\u53ef\u4f7f\u7528\u7d22\u5f15<\/strong><\/p>\n<p>\u56e0\u4e3a\u5de6\u7aef\u5b57\u6bb5 a \u6ca1\u6709\u53c2\u4e0e\u67e5\u8be2\u6761\u4ef6\u7684\u6bd4\u8f83\u3002<\/p>\n<p><strong>\u4f7f\u7528\u6307\u5357<\/strong><\/p>\n<p>\u4f7f\u7528\u8054\u5408\u7d22\u5f15\u65f6\uff0c\u8bf7\u9075\u5faa\u4ee5\u4e0b\u6307\u5357\uff1a<\/p>\n<ul>\n<li>\u5c06\u6700\u9891\u7e41\u4f7f\u7528\u7684\u5b57\u6bb5\u653e\u5728\u8054\u5408\u7d22\u5f15\u7684\u5de6\u7aef\u3002<\/li>\n<li>\u5728\u67e5\u8be2\u6761\u4ef6\u4e2d\u59cb\u7ec8\u5305\u542b\u5de6\u7aef\u5b57\u6bb5\u3002<\/li>\n<li>\u5982\u679c\u9700\u8981\u6309\u5176\u4ed6\u5b57\u6bb5\u6392\u5e8f\uff0c\u8bf7\u5c06\u8fd9\u4e9b\u5b57\u6bb5\u653e\u5728 order by \u5b50\u53e5\u4e2d\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fMySQL \u8054\u5408\u7d22\u5f15\u7684\u6700\u5de6\u524d\u7f00\u539f\u5219\uff1a\u4e3a\u4f55\u67e5\u8be2\u6761\u4ef6\u5fc5\u987b\u5305\u542b\u6700\u5de6\u4fa7\u5b57\u6bb5\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>\u4e3a\u4f55\u9700\u8981\u6700\u5de6\u524d\u7f00\u8981\u6c42 \u5728\u4f18\u5316 mysql \u67e5\u8be2\u65f6\uff0c\u6700\u5de6\u524d\u7f00\u539f\u5219\u662f\u81f3\u5173\u91cd\u8981\u7684\u3002\u5f53\u4f7f\u7528\u8054\u5408\u7d22\u5f15\u65f6\uff0c\u53ea\u6709\u6ee1\u8db3\u6700\u5de6\u524d\u7f00\u6761\u4ef6\u7684\u67e5\u8be2\u624d\u80fd\u5229\u7528\u7d22\u5f15\u3002 \u4ec0\u4e48\u662f\u6700\u5de6\u524d\u7f00\u539f\u5219 \u6700\u5de6\u524d\u7f00\u539f\u5219\u89c4\u5b9a\uff0c\u8054\u5408\u7d22\u5f15\u4e2d\u7684\u5de6\u7aef\u5b57\u6bb5\u5fc5\u987b\u53c2\u4e0e\u67e5\u8be2\u6761\u4ef6\u7684\u6bd4\u8f83\u3002\u4f8b\u5982\uff0c\u5bf9\u4e8e\u7d22\u5f15 (user_id, created_at)\uff0c\u4ee5\u4e0b\u67e5\u8be2\u53ef\u4ee5\u5229\u7528\u7d22\u5f15\uff1a select * from tweet where created_at &lt; &#8216;2021-11-11&#8217; and user_id = 1; \u767b\u5f55\u540e\u590d\u5236 \u4f18\u5316\u5668\u65e0\u6cd5\u4f18\u5316\u987a\u5e8f\u8c03\u6574 \u60a8\u63d0\u5230\u7684\u4f18\u5316\u5668\u65e0\u6cd5\u5c06\u4e0a\u8ff0\u67e5\u8be2\u4f18\u5316\u4e3a\u4ee5\u4e0b\u987a\u5e8f\uff1a SELECT * FROM tweet WHERE user_id = 1 AND created_at &lt; &#8216;2021-11-11&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u8fd9\u662f\u56e0\u4e3a\u6700\u5de6\u524d\u7f00\u539f\u5219\u9700\u8981\u5de6\u7aef\u7684\u5b57\u6bb5 user_id \u53c2\u4e0e\u67e5\u8be2\u6761\u4ef6\u7684\u6bd4\u8f83\u3002\u8df3\u8fc7 user_id \u5c06\u5bfc\u81f4\u7d22\u5f15\u65e0\u6cd5\u4f7f\u7528\u3002 \u5de6\u524d\u7f00\u793a\u4f8b \u4e3a\u4e86\u8fdb\u4e00\u6b65\u7406\u89e3\u6700\u5de6\u524d\u7f00\u539f\u5219\uff0c\u8bf7\u8003\u8651\u4ee5\u4e0b\u793a\u4f8b\uff1a \u7d22\u5f15 (a, b, c) \u67e5\u8be2\u6761\u4ef6\uff1aa = 1 \u6b64\u5904\u53ef\u4f7f\u7528\u7d22\u5f15 \u56e0\u4e3a\u5de6\u7aef\u5b57\u6bb5 a \u53c2\u4e0e\u4e86\u67e5\u8be2\u6761\u4ef6\u7684\u6bd4\u8f83\u3002 \u67e5\u8be2\u6761\u4ef6\uff1ac [&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-6891","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6891","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=6891"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6891\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6891"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6891"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6891"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}