{"id":5726,"date":"2024-11-14T09:25:12","date_gmt":"2024-11-14T01:25:12","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5726\/"},"modified":"2024-11-14T09:25:12","modified_gmt":"2024-11-14T01:25:12","slug":"sql%e6%97%b6%e9%97%b4%e6%80%8e%e4%b9%88%e6%af%94%e8%be%83","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5726\/","title":{"rendered":"sql\u65f6\u95f4\u600e\u4e48\u6bd4\u8f83"},"content":{"rendered":"<blockquote><p>\n  \u5728 sql \u4e2d\uff0c\u6bd4\u8f83\u65f6\u95f4\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a1\u3001\u76f4\u63a5\u6bd4\u8f83\u65f6\u95f4\u503c\uff1b2\u3001\u4f7f\u7528\u65e5\u671f\u548c\u65f6\u95f4\u51fd\u6570\u63d0\u53d6\u65f6\u95f4\u4e0d\u540c\u90e8\u5206\u540e\u518d\u6bd4\u8f83\uff08\u5982\u6bd4\u8f83\u5e74\u4efd\u3001\u6708\u4efd\u7b49\uff09\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/30\/2024053021275596818.jpg\" class=\"aligncenter\" title=\"sql\u65f6\u95f4\u600e\u4e48\u6bd4\u8f83\u63d2\u56fe\" alt=\"sql\u65f6\u95f4\u600e\u4e48\u6bd4\u8f83\u63d2\u56fe\" \/><\/p>\n<p><strong>SQL \u4e2d\u6bd4\u8f83\u65f6\u95f4\u7684\u4e24\u79cd\u65b9\u6cd5<\/strong><\/p>\n<p>\u5728 SQL \u4e2d\uff0c\u6bd4\u8f83\u65f6\u95f4\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4e24\u79cd\u65b9\u6cd5\uff1a<\/p>\n<p><strong>1. \u76f4\u63a5\u6bd4\u8f83<\/strong><\/p>\n<p>\u76f4\u63a5\u6bd4\u8f83\u662f\u6700\u7b80\u5355\u7684\u65b9\u6cd5\uff0c\u5b83\u5c06\u4e24\u4e2a\u65f6\u95f4\u503c\u76f4\u63a5\u6bd4\u8f83\u3002\u5982\u679c\u4e24\u4e2a\u503c\u76f8\u7b49\uff0c\u5219\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false\u3002<\/p>\n<pre>SELECT CASE\n    WHEN time_field1 = time_field2\n    THEN true\n    ELSE false\nEND<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>2. \u4f7f\u7528\u65e5\u671f\u548c\u65f6\u95f4\u51fd\u6570<\/strong><\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u65e5\u671f\u548c\u65f6\u95f4\u51fd\u6570\u6765\u6bd4\u8f83\u4e24\u4e2a\u65f6\u95f4\u503c\u3002\u8fd9\u4e9b\u51fd\u6570\u53ef\u4ee5\u63d0\u53d6\u65f6\u95f4\u7684\u4e0d\u540c\u90e8\u5206\uff0c\u4f8b\u5982\u5e74\u3001\u6708\u6216\u5929\uff0c\u7136\u540e\u5c06\u8fd9\u4e9b\u90e8\u5206\u8fdb\u884c\u6bd4\u8f83\u3002<\/p>\n<p>\u4f8b\u5982\uff0c\u4ee5\u4e0b\u67e5\u8be2\u6bd4\u8f83\u4e24\u5217\u65f6\u95f4\u503c\u7684\u5e74\u4efd\uff1a<\/p>\n<pre>SELECT CASE\n    WHEN YEAR(time_field1) = YEAR(time_field2)\n    THEN true\n    ELSE false\nEND<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u65e5\u671f\u548c\u65f6\u95f4\u51fd\u6570\u6765\u6bd4\u8f83\u5176\u4ed6\u65f6\u95f4\u90e8\u5206\uff0c\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li>YEAR() &#8211; \u8fd4\u56de\u5e74\u4efd<\/li>\n<li>MONTH() &#8211; \u8fd4\u56de\u6708\u4efd<\/li>\n<li>DAY() &#8211; \u8fd4\u56de\u5929\u6570<\/li>\n<li>HOUR() &#8211; \u8fd4\u56de\u5c0f\u65f6\u6570<\/li>\n<li>MINUTE() &#8211; \u8fd4\u56de\u5206\u949f\u6570<\/li>\n<li>SECOND() &#8211; \u8fd4\u56de\u79d2\u6570<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662fsql\u65f6\u95f4\u600e\u4e48\u6bd4\u8f83\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 sql \u4e2d\uff0c\u6bd4\u8f83\u65f6\u95f4\u6709\u4e24\u79cd\u65b9\u6cd5\uff1a1\u3001\u76f4\u63a5\u6bd4\u8f83\u65f6\u95f4\u503c\uff1b2\u3001\u4f7f\u7528\u65e5\u671f\u548c\u65f6\u95f4\u51fd\u6570\u63d0\u53d6\u65f6\u95f4\u4e0d\u540c\u90e8\u5206\u540e\u518d\u6bd4\u8f83\uff08\u5982\u6bd4\u8f83\u5e74\u4efd\u3001\u6708\u4efd\u7b49\uff09\u3002 SQL \u4e2d\u6bd4\u8f83\u65f6\u95f4\u7684\u4e24\u79cd\u65b9\u6cd5 \u5728 SQL \u4e2d\uff0c\u6bd4\u8f83\u65f6\u95f4\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u4e24\u79cd\u65b9\u6cd5\uff1a 1. \u76f4\u63a5\u6bd4\u8f83 \u76f4\u63a5\u6bd4\u8f83\u662f\u6700\u7b80\u5355\u7684\u65b9\u6cd5\uff0c\u5b83\u5c06\u4e24\u4e2a\u65f6\u95f4\u503c\u76f4\u63a5\u6bd4\u8f83\u3002\u5982\u679c\u4e24\u4e2a\u503c\u76f8\u7b49\uff0c\u5219\u8fd4\u56de true\uff0c\u5426\u5219\u8fd4\u56de false\u3002 SELECT CASE WHEN time_field1 = time_field2 THEN true ELSE false END \u767b\u5f55\u540e\u590d\u5236 2. \u4f7f\u7528\u65e5\u671f\u548c\u65f6\u95f4\u51fd\u6570 \u53ef\u4ee5\u4f7f\u7528\u65e5\u671f\u548c\u65f6\u95f4\u51fd\u6570\u6765\u6bd4\u8f83\u4e24\u4e2a\u65f6\u95f4\u503c\u3002\u8fd9\u4e9b\u51fd\u6570\u53ef\u4ee5\u63d0\u53d6\u65f6\u95f4\u7684\u4e0d\u540c\u90e8\u5206\uff0c\u4f8b\u5982\u5e74\u3001\u6708\u6216\u5929\uff0c\u7136\u540e\u5c06\u8fd9\u4e9b\u90e8\u5206\u8fdb\u884c\u6bd4\u8f83\u3002 \u4f8b\u5982\uff0c\u4ee5\u4e0b\u67e5\u8be2\u6bd4\u8f83\u4e24\u5217\u65f6\u95f4\u503c\u7684\u5e74\u4efd\uff1a SELECT CASE WHEN YEAR(time_field1) = YEAR(time_field2) THEN true ELSE false END \u767b\u5f55\u540e\u590d\u5236 \u53ef\u4ee5\u4f7f\u7528\u5176\u4ed6\u65e5\u671f\u548c\u65f6\u95f4\u51fd\u6570\u6765\u6bd4\u8f83\u5176\u4ed6\u65f6\u95f4\u90e8\u5206\uff0c\u4f8b\u5982\uff1a YEAR() &#8211; \u8fd4\u56de\u5e74\u4efd MONTH() &#8211; \u8fd4\u56de\u6708\u4efd DAY() &#8211; \u8fd4\u56de\u5929\u6570 HOUR() &#8211; \u8fd4\u56de\u5c0f\u65f6\u6570 MINUTE() [&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-5726","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5726","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=5726"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5726\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5726"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5726"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5726"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}