{"id":6407,"date":"2024-11-14T12:55:30","date_gmt":"2024-11-14T04:55:30","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6407\/"},"modified":"2024-11-14T12:55:30","modified_gmt":"2024-11-14T04:55:30","slug":"mysql%e6%9f%a5%e8%af%a2%e6%9f%90%e4%b8%80%e5%a4%a9%e7%9a%84%e6%95%b0%e6%8d%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6407\/","title":{"rendered":"mysql\u67e5\u8be2\u67d0\u4e00\u5929\u7684\u6570\u636e"},"content":{"rendered":"<blockquote><p>\n  \u67e5\u8be2 mysql \u67d0\u4e00\u5929\u7684\u6570\u636e\u6709\u4e09\u79cd\u65b9\u6cd5\uff1a1. \u4f7f\u7528 date() \u51fd\u6570\uff0c\u4ec5\u8fd4\u56de\u65e5\u671f\u90e8\u5206\uff1b2. \u4f7f\u7528 between \u8fd0\u7b97\u7b26\uff0c\u6307\u5b9a\u65e5\u671f\u8303\u56f4\uff1b3. \u4f7f\u7528 curdate() \u51fd\u6570\uff0c\u8fd4\u56de\u4eca\u5929\u7684\u65e5\u671f\u5e76\u67e5\u8be2\u7279\u5b9a\u65e5\u671f\u7684\u504f\u79fb\u91cf\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/01\/2024080121400194972.jpg\" class=\"aligncenter\" title=\"mysql\u67e5\u8be2\u67d0\u4e00\u5929\u7684\u6570\u636e\u63d2\u56fe\" alt=\"mysql\u67e5\u8be2\u67d0\u4e00\u5929\u7684\u6570\u636e\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u67e5\u8be2 MySQL \u67d0\u4e00\u5929\u7684\u6570\u636e<\/strong><\/p>\n<p><strong>\u65b9\u6cd5 1\uff1a\u4f7f\u7528 DATE() \u51fd\u6570<\/strong><\/p>\n<p>\u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u4f7f\u7528 DATE() \u51fd\u6570\uff0c\u5b83\u4ec5\u8fd4\u56de\u65e5\u671f\u90e8\u5206\uff1a<\/p>\n<pre>SELECT * FROM table_name\nWHERE DATE(date_column) = '2023-05-10';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u65b9\u6cd5 2\uff1a\u4f7f\u7528 BETWEEN \u8fd0\u7b97\u7b26<\/strong><\/p>\n<p>BETWEEN \u8fd0\u7b97\u7b26\u5141\u8bb8\u60a8\u6307\u5b9a\u4e00\u4e2a\u65e5\u671f\u8303\u56f4\uff1a<\/p>\n<pre>SELECT * FROM table_name\nWHERE date_column BETWEEN '2023-05-10' AND '2023-05-10 23:59:59';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u65b9\u6cd5 3\uff1a\u4f7f\u7528 CURDATE() \u51fd\u6570<\/strong><\/p>\n<p>CURDATE() \u51fd\u6570\u8fd4\u56de\u4eca\u5929\u7684\u65e5\u671f\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u67e5\u8be2\u7279\u5b9a\u65e5\u671f\u7684\u504f\u79fb\u91cf\uff1a<\/p>\n<pre>SELECT * FROM table_name\nWHERE date_column &gt;= CURDATE() - INTERVAL 1 DAY\nAND date_column &lt; CURDATE();<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u5047\u8bbe\u60a8\u6709\u4e00\u4e2a\u540d\u4e3a orders \u7684\u8868\uff0c\u5176\u4e2d\u5305\u542b date \u5217\u3002\u8981\u67e5\u627e 2023 \u5e74 5 \u6708 10 \u65e5\u6240\u6709\u8ba2\u5355\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8be2\uff1a<\/p>\n<pre>SELECT * FROM orders\nWHERE DATE(date) = '2023-05-10';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd date_column \u7684\u6570\u636e\u7c7b\u578b\u4e3a DATE \u6216 DATETIME\u3002<\/li>\n<li>\u4f7f\u7528 DATE() \u51fd\u6570\u65f6\uff0c\u65f6\u95f4\u90e8\u5206\u5c06\u88ab\u622a\u65ad\u3002<\/li>\n<li>\u4f7f\u7528 BETWEEN \u8fd0\u7b97\u7b26\u65f6\uff0c\u8303\u56f4\u7684\u672b\u7aef\u503c\u5e94\u5305\u542b\u65f6\u95f4\u90e8\u5206\uff0c\u4ee5\u786e\u4fdd\u67e5\u8be2\u5305\u542b\u6574\u4e2a\u4e00\u5929\u7684\u6570\u636e\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u67e5\u8be2\u67d0\u4e00\u5929\u7684\u6570\u636e\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>\u67e5\u8be2 mysql \u67d0\u4e00\u5929\u7684\u6570\u636e\u6709\u4e09\u79cd\u65b9\u6cd5\uff1a1. \u4f7f\u7528 date() \u51fd\u6570\uff0c\u4ec5\u8fd4\u56de\u65e5\u671f\u90e8\u5206\uff1b2. \u4f7f\u7528 between \u8fd0\u7b97\u7b26\uff0c\u6307\u5b9a\u65e5\u671f\u8303\u56f4\uff1b3. \u4f7f\u7528 curdate() \u51fd\u6570\uff0c\u8fd4\u56de\u4eca\u5929\u7684\u65e5\u671f\u5e76\u67e5\u8be2\u7279\u5b9a\u65e5\u671f\u7684\u504f\u79fb\u91cf\u3002 \u5982\u4f55\u67e5\u8be2 MySQL \u67d0\u4e00\u5929\u7684\u6570\u636e \u65b9\u6cd5 1\uff1a\u4f7f\u7528 DATE() \u51fd\u6570 \u6700\u7b80\u5355\u7684\u65b9\u6cd5\u662f\u4f7f\u7528 DATE() \u51fd\u6570\uff0c\u5b83\u4ec5\u8fd4\u56de\u65e5\u671f\u90e8\u5206\uff1a SELECT * FROM table_name WHERE DATE(date_column) = &#8216;2023-05-10&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u65b9\u6cd5 2\uff1a\u4f7f\u7528 BETWEEN \u8fd0\u7b97\u7b26 BETWEEN \u8fd0\u7b97\u7b26\u5141\u8bb8\u60a8\u6307\u5b9a\u4e00\u4e2a\u65e5\u671f\u8303\u56f4\uff1a SELECT * FROM table_name WHERE date_column BETWEEN &#8216;2023-05-10&#8217; AND &#8216;2023-05-10 23:59:59&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u65b9\u6cd5 3\uff1a\u4f7f\u7528 CURDATE() \u51fd\u6570 CURDATE() \u51fd\u6570\u8fd4\u56de\u4eca\u5929\u7684\u65e5\u671f\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u67e5\u8be2\u7279\u5b9a\u65e5\u671f\u7684\u504f\u79fb\u91cf\uff1a [&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-6407","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6407","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=6407"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6407\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6407"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6407"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6407"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}