{"id":6894,"date":"2024-11-14T09:29:27","date_gmt":"2024-11-14T01:29:27","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6894\/"},"modified":"2024-11-14T09:29:27","modified_gmt":"2024-11-14T01:29:27","slug":"%e4%b8%ba%e4%bb%80%e4%b9%88-mysql-%e4%bc%98%e5%8c%96%e5%99%a8%e6%97%a0%e6%b3%95%e8%87%aa%e5%8a%a8%e4%bc%98%e5%8c%96%e8%81%94%e5%90%88%e7%b4%a2%e5%bc%95%e9%a1%ba%e5%ba%8f%ef%bc%8c%e9%9c%80%e8%a6%81","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6894\/","title":{"rendered":"\u4e3a\u4ec0\u4e48 MySQL \u4f18\u5316\u5668\u65e0\u6cd5\u81ea\u52a8\u4f18\u5316\u8054\u5408\u7d22\u5f15\u987a\u5e8f\uff0c\u9700\u8981\u5f00\u53d1\u8005\u9075\u5faa\u6700\u5de6\u524d\u7f00\u539f\u5219\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173002807152627.jpg\" class=\"aligncenter\" title=\"\u4e3a\u4ec0\u4e48 MySQL \u4f18\u5316\u5668\u65e0\u6cd5\u81ea\u52a8\u4f18\u5316\u8054\u5408\u7d22\u5f15\u987a\u5e8f\uff0c\u9700\u8981\u5f00\u53d1\u8005\u9075\u5faa\u6700\u5de6\u524d\u7f00\u539f\u5219\uff1f\u63d2\u56fe\" alt=\"\u4e3a\u4ec0\u4e48 MySQL \u4f18\u5316\u5668\u65e0\u6cd5\u81ea\u52a8\u4f18\u5316\u8054\u5408\u7d22\u5f15\u987a\u5e8f\uff0c\u9700\u8981\u5f00\u53d1\u8005\u9075\u5faa\u6700\u5de6\u524d\u7f00\u539f\u5219\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong> \u6700\u5de6\u524d\u7f00\u539f\u5219\u63ed\u79d8\uff1a\u4f18\u5316\u5668\u4e3a\u4f55\u65e0\u6cd5\u81ea\u52a8\u4f18\u5316\u987a\u5e8f<\/strong><\/p>\n<p>\u5728\u4f7f\u7528 mysql \u8054\u5408\u7d22\u5f15\u65f6\uff0c\u9700\u8981\u9075\u5faa\u6700\u5de6\u524d\u7f00\u539f\u5219\u3002\u800c\u6709\u4e9b\u5f00\u53d1\u8005\u53ef\u80fd\u4f1a\u7591\u60d1\uff0c\u4e3a\u4f55\u4f18\u5316\u5668\u4e0d\u80fd\u81ea\u52a8\u4f18\u5316\u987a\u5e8f\uff0c\u4ece\u800c\u5ffd\u7565\u6700\u5de6\u524d\u7f00\u539f\u5219\u3002<\/p>\n<p><strong>\u6700\u5de6\u524d\u7f00\u539f\u5219\u7684\u5fc5\u8981\u6027<\/strong><\/p>\n<p>\u6700\u5de6\u524d\u7f00\u539f\u5219\u8981\u6c42\u7d22\u5f15\u7684\u7b2c\u4e00\u4e2a\u5b57\u6bb5\u5fc5\u987b\u51fa\u73b0\u5728 where \u6761\u4ef6\u4e2d\uff0c\u4e14\u4e0d\u53ef\u7701\u7565\u3002\u8fd9\u662f\u56e0\u4e3a mysql \u7d22\u5f15\u662f\u4e00\u79cd\u6709\u5e8f\u7ed3\u6784\uff0c\u53ea\u80fd\u4ece\u5de6\u5230\u53f3\u626b\u63cf\u3002\u5982\u679c where \u6761\u4ef6\u6ca1\u6709\u9075\u5faa\u6700\u5de6\u524d\u7f00\u539f\u5219\uff0c\u4f18\u5316\u5668\u5c31\u65e0\u6cd5\u76f4\u63a5\u5bfb\u5740\u7d22\u5f15\uff0c\u5bfc\u81f4\u67e5\u8be2\u6548\u7387\u4f4e\u4e0b\u3002<\/p>\n<p><strong>\u5bfc\u81f4\u67e5\u8be2\u65e0\u6cd5\u4f7f\u7528\u7d22\u5f15\u7684\u573a\u666f<\/strong><\/p>\n<p>\u6bd4\u5982\uff0c\u4e00\u4e2a\u8054\u5408\u7d22\u5f15\u4e3a (user_id, created_at)\uff0c\u5047\u5982\u6211\u4eec\u4e66\u5199\u5982\u4e0b sql \u8bed\u53e5\uff1a<\/p>\n<pre>select *\nfrom tweet\nwhere created_at &lt; '2021-11-11'\nand user_id = 1;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5982\u679c\u672a\u9075\u5faa\u6700\u5de6\u524d\u7f00\u539f\u5219\uff0c\u4f18\u5316\u5668\u65e0\u6cd5\u76f4\u63a5\u5bfb\u5740\u7d22\u5f15\uff0c\u53ea\u80fd\u5168\u8868\u626b\u63cf\u6765\u6ee1\u8db3\u67e5\u8be2\u8bf7\u6c42\u3002<\/p>\n<p><strong>\u7b26\u5408\u6700\u5de6\u524d\u7f00\u539f\u5219\u7684\u573a\u666f<\/strong><\/p>\n<p>\u6b63\u786e\u7684\u4f18\u5316\u65b9\u6cd5\u662f\uff1a<\/p>\n<pre>SELECT *\nFROM tweet\nWHERE user_id = 1\nAND created_at &lt; '2021-11-11';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u56e0\u4e3a user_id \u662f\u8054\u5408\u7d22\u5f15\u7684\u7b2c\u4e00\u4e2a\u5b57\u6bb5\uff0c\u9075\u5faa\u4e86\u6700\u5de6\u524d\u7f00\u539f\u5219\uff0c\u56e0\u6b64\u4f18\u5316\u5668\u53ef\u4ee5\u901a\u8fc7\u7d22\u5f15\u9ad8\u6548\u5b9a\u4f4d\u7b26\u5408\u6761\u4ef6\u7684\u6570\u636e\u3002<\/p>\n<p><strong>\u5de6\u524d\u7f00\u539f\u5219\u6982\u62ec<\/strong><\/p>\n<p>\u603b\u7684\u6765\u8bf4\uff0c\u5de6\u524d\u7f00\u539f\u5219\u8981\u6c42\u8054\u5408\u7d22\u5f15\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5b57\u6bb5\u5fc5\u987b\u51fa\u73b0\u5728 where \u6761\u4ef6\u4e2d\uff0c\u4e14\u540e\u5e8f\u5b57\u6bb5\u53ef\u4ee5\u4efb\u610f\u7ec4\u5408\u3002\u5982 (a, b, c) \u7d22\u5f15\uff0cwhere \u6761\u4ef6\u53ef\u4ee5\u662f a, b, c\u3001a, c\u3001a, b\u3001a \u7b49\uff0c\u4f46\u4e0d\u80fd\u662f b, c \u6216 c, a\u3002<\/p>\n<p><strong>\u672a\u9075\u5faa\u6700\u5de6\u524d\u7f00\u539f\u5219\u7684\u8868\u8ff0\u793a\u4f8b<\/strong><\/p>\n<p>\u4e3a\u4e86\u8fdb\u4e00\u6b65\u7406\u89e3\uff0c\u4ee5\u4e0b\u4e3a\u672a\u9075\u5faa\u6700\u5de6\u524d\u7f00\u539f\u5219\u7684\u8868\u8ff0\uff1a<\/p>\n<ul>\n<li>created_at <\/li>\n<li>user_id = 1\uff0c\u65e0\u6cd5\u4f7f\u7528\u8054\u5408\u7d22\u5f15 (a, b, c)\uff0c\u56e0\u4e3a\u6ca1\u6709\u4f7f\u7528\u7d22\u5f15\u7684\u7b2c\u4e00\u4e2a\u5b57\u6bb5 a\u3002<\/li>\n<li>where b, c\uff0c\u65e0\u6cd5\u4f7f\u7528\u8054\u5408\u7d22\u5f15 (a, b, c)\uff0c\u56e0\u4e3a\u6ca1\u6709\u51fa\u73b0\u7d22\u5f15\u7684\u7b2c\u4e00\u4e2a\u5b57\u6bb5 a\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u4e3a\u4ec0\u4e48 MySQL \u4f18\u5316\u5668\u65e0\u6cd5\u81ea\u52a8\u4f18\u5316\u8054\u5408\u7d22\u5f15\u987a\u5e8f\uff0c\u9700\u8981\u5f00\u53d1\u8005\u9075\u5faa\u6700\u5de6\u524d\u7f00\u539f\u5219\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>\u6700\u5de6\u524d\u7f00\u539f\u5219\u63ed\u79d8\uff1a\u4f18\u5316\u5668\u4e3a\u4f55\u65e0\u6cd5\u81ea\u52a8\u4f18\u5316\u987a\u5e8f \u5728\u4f7f\u7528 mysql \u8054\u5408\u7d22\u5f15\u65f6\uff0c\u9700\u8981\u9075\u5faa\u6700\u5de6\u524d\u7f00\u539f\u5219\u3002\u800c\u6709\u4e9b\u5f00\u53d1\u8005\u53ef\u80fd\u4f1a\u7591\u60d1\uff0c\u4e3a\u4f55\u4f18\u5316\u5668\u4e0d\u80fd\u81ea\u52a8\u4f18\u5316\u987a\u5e8f\uff0c\u4ece\u800c\u5ffd\u7565\u6700\u5de6\u524d\u7f00\u539f\u5219\u3002 \u6700\u5de6\u524d\u7f00\u539f\u5219\u7684\u5fc5\u8981\u6027 \u6700\u5de6\u524d\u7f00\u539f\u5219\u8981\u6c42\u7d22\u5f15\u7684\u7b2c\u4e00\u4e2a\u5b57\u6bb5\u5fc5\u987b\u51fa\u73b0\u5728 where \u6761\u4ef6\u4e2d\uff0c\u4e14\u4e0d\u53ef\u7701\u7565\u3002\u8fd9\u662f\u56e0\u4e3a mysql \u7d22\u5f15\u662f\u4e00\u79cd\u6709\u5e8f\u7ed3\u6784\uff0c\u53ea\u80fd\u4ece\u5de6\u5230\u53f3\u626b\u63cf\u3002\u5982\u679c where \u6761\u4ef6\u6ca1\u6709\u9075\u5faa\u6700\u5de6\u524d\u7f00\u539f\u5219\uff0c\u4f18\u5316\u5668\u5c31\u65e0\u6cd5\u76f4\u63a5\u5bfb\u5740\u7d22\u5f15\uff0c\u5bfc\u81f4\u67e5\u8be2\u6548\u7387\u4f4e\u4e0b\u3002 \u5bfc\u81f4\u67e5\u8be2\u65e0\u6cd5\u4f7f\u7528\u7d22\u5f15\u7684\u573a\u666f \u6bd4\u5982\uff0c\u4e00\u4e2a\u8054\u5408\u7d22\u5f15\u4e3a (user_id, created_at)\uff0c\u5047\u5982\u6211\u4eec\u4e66\u5199\u5982\u4e0b sql \u8bed\u53e5\uff1a select * from tweet where created_at &lt; &#8216;2021-11-11&#8217; and user_id = 1; \u767b\u5f55\u540e\u590d\u5236 \u5982\u679c\u672a\u9075\u5faa\u6700\u5de6\u524d\u7f00\u539f\u5219\uff0c\u4f18\u5316\u5668\u65e0\u6cd5\u76f4\u63a5\u5bfb\u5740\u7d22\u5f15\uff0c\u53ea\u80fd\u5168\u8868\u626b\u63cf\u6765\u6ee1\u8db3\u67e5\u8be2\u8bf7\u6c42\u3002 \u7b26\u5408\u6700\u5de6\u524d\u7f00\u539f\u5219\u7684\u573a\u666f \u6b63\u786e\u7684\u4f18\u5316\u65b9\u6cd5\u662f\uff1a SELECT * FROM tweet WHERE user_id = 1 AND created_at &lt; &#8216;2021-11-11&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u56e0\u4e3a user_id \u662f\u8054\u5408\u7d22\u5f15\u7684\u7b2c\u4e00\u4e2a\u5b57\u6bb5\uff0c\u9075\u5faa\u4e86\u6700\u5de6\u524d\u7f00\u539f\u5219\uff0c\u56e0\u6b64\u4f18\u5316\u5668\u53ef\u4ee5\u901a\u8fc7\u7d22\u5f15\u9ad8\u6548\u5b9a\u4f4d\u7b26\u5408\u6761\u4ef6\u7684\u6570\u636e\u3002 \u5de6\u524d\u7f00\u539f\u5219\u6982\u62ec \u603b\u7684\u6765\u8bf4\uff0c\u5de6\u524d\u7f00\u539f\u5219\u8981\u6c42\u8054\u5408\u7d22\u5f15\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5b57\u6bb5\u5fc5\u987b\u51fa\u73b0\u5728 where \u6761\u4ef6\u4e2d\uff0c\u4e14\u540e\u5e8f\u5b57\u6bb5\u53ef\u4ee5\u4efb\u610f\u7ec4\u5408\u3002\u5982 (a, [&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-6894","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6894","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=6894"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6894\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6894"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6894"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6894"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}