{"id":7057,"date":"2024-11-14T12:04:15","date_gmt":"2024-11-14T04:04:15","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7057\/"},"modified":"2024-11-14T12:04:15","modified_gmt":"2024-11-14T04:04:15","slug":"mysql-%e5%a6%82%e4%bd%95%e6%a3%80%e7%b4%a2%e5%bd%93%e6%97%a5%e6%95%b0%e6%8d%ae%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7057\/","title":{"rendered":"MySQL \u5982\u4f55\u68c0\u7d22\u5f53\u65e5\u6570\u636e\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173036513265843.jpg\" class=\"aligncenter\" title=\"MySQL \u5982\u4f55\u68c0\u7d22\u5f53\u65e5\u6570\u636e\uff1f\u63d2\u56fe\" alt=\"MySQL \u5982\u4f55\u68c0\u7d22\u5f53\u65e5\u6570\u636e\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5728  \u4e2d\u68c0\u7d22\u5f53\u65e5\u6570\u636e<\/strong><\/p>\n<p>\u5728 mysql \u6570\u636e\u5e93\u4e2d\uff0c\u9488\u5bf9\u7279\u5b9a\u8bb0\u5f55\u67e5\u8be2\u5f53\u5929\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528 to_days() \u51fd\u6570\uff0c\u8be5\u51fd\u6570\u5c06\u65f6\u95f4\u6233\u503c\u8f6c\u6362\u4e3a\u65e5\u671f\uff0c\u5e76\u4e0e\u5f53\u524d\u65e5\u671f\u8fdb\u884c\u6bd4\u8f83\u3002<\/p>\n<p><strong>\u67e5\u8be2\u65b9\u6cd5\uff1a<\/strong><\/p>\n<p>\u4ee5\u4e0b\u67e5\u8be2\u53ef\u4ee5\u4ece\u540d\u4e3a comment \u7684\u8868\u4e2d\u68c0\u7d22 id \u4e3a 21 \u7684\u8bb0\u5f55\uff0c\u5176 create_time \u5b57\u6bb5\u503c\u4ee3\u8868\u5f53\u5929\uff1a<\/p>\n<pre>select * from comment where to_days(create_time) = to_days(now()) and id = 21;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u7528\u6cd5\u8bf4\u660e\uff1a<\/strong><\/p>\n<ul>\n<li>to_days(create_time) \u5c06 create_time \u5b57\u6bb5\u503c\u8f6c\u6362\u4e3a\u65e5\u671f\u3002<\/li>\n<li>to_days(now()) \u83b7\u53d6\u5f53\u524d\u65e5\u671f\u3002<\/li>\n<li>\u5c06\u8fd9\u4e24\u4e2a\u65e5\u671f\u503c\u8fdb\u884c\u6bd4\u8f83\uff0c\u4ee5\u786e\u5b9a create_time \u5b57\u6bb5\u503c\u662f\u5426\u4ee3\u8868\u5f53\u5929\u3002<\/li>\n<li>\u6b64\u5916\uff0c\u6dfb\u52a0\u4e86 id = 21 \u6761\u4ef6\u4ee5\u8fc7\u6ee4\u7279\u5b9a\u8bb0\u5f55\u3002<\/li>\n<\/ul>\n<p>\u4e0a\u8ff0\u67e5\u8be2\u5c06\u8fd4\u56de\u6ee1\u8db3\u6307\u5b9a\u6761\u4ef6\u7684\u6240\u6709\u8bb0\u5f55\uff0c\u5373 create_time \u5b57\u6bb5\u503c\u4ee3\u8868\u5f53\u5929\u4e14 id \u4e3a 21\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fMySQL \u5982\u4f55\u68c0\u7d22\u5f53\u65e5\u6570\u636e\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>\u5728 \u4e2d\u68c0\u7d22\u5f53\u65e5\u6570\u636e \u5728 mysql \u6570\u636e\u5e93\u4e2d\uff0c\u9488\u5bf9\u7279\u5b9a\u8bb0\u5f55\u67e5\u8be2\u5f53\u5929\u6570\u636e\uff0c\u53ef\u4ee5\u4f7f\u7528 to_days() \u51fd\u6570\uff0c\u8be5\u51fd\u6570\u5c06\u65f6\u95f4\u6233\u503c\u8f6c\u6362\u4e3a\u65e5\u671f\uff0c\u5e76\u4e0e\u5f53\u524d\u65e5\u671f\u8fdb\u884c\u6bd4\u8f83\u3002 \u67e5\u8be2\u65b9\u6cd5\uff1a \u4ee5\u4e0b\u67e5\u8be2\u53ef\u4ee5\u4ece\u540d\u4e3a comment \u7684\u8868\u4e2d\u68c0\u7d22 id \u4e3a 21 \u7684\u8bb0\u5f55\uff0c\u5176 create_time \u5b57\u6bb5\u503c\u4ee3\u8868\u5f53\u5929\uff1a select * from comment where to_days(create_time) = to_days(now()) and id = 21; \u767b\u5f55\u540e\u590d\u5236 \u7528\u6cd5\u8bf4\u660e\uff1a to_days(create_time) \u5c06 create_time \u5b57\u6bb5\u503c\u8f6c\u6362\u4e3a\u65e5\u671f\u3002 to_days(now()) \u83b7\u53d6\u5f53\u524d\u65e5\u671f\u3002 \u5c06\u8fd9\u4e24\u4e2a\u65e5\u671f\u503c\u8fdb\u884c\u6bd4\u8f83\uff0c\u4ee5\u786e\u5b9a create_time \u5b57\u6bb5\u503c\u662f\u5426\u4ee3\u8868\u5f53\u5929\u3002 \u6b64\u5916\uff0c\u6dfb\u52a0\u4e86 id = 21 \u6761\u4ef6\u4ee5\u8fc7\u6ee4\u7279\u5b9a\u8bb0\u5f55\u3002 \u4e0a\u8ff0\u67e5\u8be2\u5c06\u8fd4\u56de\u6ee1\u8db3\u6307\u5b9a\u6761\u4ef6\u7684\u6240\u6709\u8bb0\u5f55\uff0c\u5373 create_time \u5b57\u6bb5\u503c\u4ee3\u8868\u5f53\u5929\u4e14 id \u4e3a 21\u3002 \u4ee5\u4e0a\u5c31\u662fMySQL \u5982\u4f55\u68c0\u7d22\u5f53\u65e5\u6570\u636e\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},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-7057","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7057","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=7057"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7057\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7057"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7057"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7057"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}