{"id":5903,"date":"2024-11-14T13:12:32","date_gmt":"2024-11-14T05:12:32","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5903\/"},"modified":"2024-11-14T13:12:32","modified_gmt":"2024-11-14T05:12:32","slug":"sql%e6%97%b6%e9%97%b4%e5%b1%9e%e6%80%a7%e6%80%8e%e4%b9%88%e6%af%94%e5%a4%a7%e5%b0%8f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5903\/","title":{"rendered":"sql\u65f6\u95f4\u5c5e\u6027\u600e\u4e48\u6bd4\u5927\u5c0f"},"content":{"rendered":"<blockquote><p>\n  \u5728 sql \u4e2d\u6bd4\u8f83\u65f6\u95f4\u5c5e\u6027\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8fd0\u7b97\u7b26\uff1a=\u3001\u3001\u3001=\uff0c\u9700\u8981\u5c0f\u5fc3\u6bd4\u8f83\u4e0d\u540c\u7c7b\u578b\u7684\u65f6\u95f4\u5c5e\u6027\u3002\u6bd4\u8f83\u65f6\u9700\u8003\u8651 null \u503c\uff0c\u53ef\u4ee5\u4f7f\u7528 is null \u548c is not null \u8fd0\u7b97\u7b26\u68c0\u67e5 null \u503c\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/03\/2024060322033586903.jpg\" class=\"aligncenter\" title=\"sql\u65f6\u95f4\u5c5e\u6027\u600e\u4e48\u6bd4\u5927\u5c0f\u63d2\u56fe\" alt=\"sql\u65f6\u95f4\u5c5e\u6027\u600e\u4e48\u6bd4\u5927\u5c0f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u6bd4\u8f83 SQL \u4e2d\u7684\u65f6\u95f4\u5c5e\u6027<\/strong><\/p>\n<p>\u5728 SQL \u4e2d\u6bd4\u8f83\u65f6\u95f4\u5c5e\u6027\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u8fd0\u7b97\u7b26\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li> <strong>=<\/strong>\uff1a\u68c0\u67e5\u65f6\u95f4\u5c5e\u6027\u662f\u5426\u76f8\u7b49\u3002<\/li>\n<li> <strong><\/strong>\uff1a\u68c0\u67e5\u65f6\u95f4\u5c5e\u6027\u662f\u5426\u4e0d\u76f8\u7b49\u3002<\/li>\n<li><strong>\uff1a\u68c0\u67e5\u65f6\u95f4\u5c5e\u6027\u662f\u5426\u65e9\u4e8e\u53e6\u4e00\u4e2a\u65f6\u95f4\u5c5e\u6027\u3002<\/strong><\/li>\n<li> <strong>&gt;<\/strong>\uff1a\u68c0\u67e5\u65f6\u95f4\u5c5e\u6027\u662f\u5426\u665a\u4e8e\u53e6\u4e00\u4e2a\u65f6\u95f4\u5c5e\u6027\u3002<\/li>\n<li><strong>\uff1a\u68c0\u67e5\u65f6\u95f4\u5c5e\u6027\u662f\u5426\u65e9\u4e8e\u6216\u7b49\u4e8e\u53e6\u4e00\u4e2a\u65f6\u95f4\u5c5e\u6027\u3002<\/strong><\/li>\n<li> <strong>&gt;=<\/strong>\uff1a\u68c0\u67e5\u65f6\u95f4\u5c5e\u6027\u662f\u5426\u665a\u4e8e\u6216\u7b49\u4e8e\u53e6\u4e00\u4e2a\u65f6\u95f4\u5c5e\u6027\u3002<\/li>\n<\/ul>\n<p><strong>\u6bd4\u8f83\u4e0d\u540c\u7c7b\u578b\u7684\u65f6\u95f4\u5c5e\u6027<\/strong><\/p>\n<p>\u6bd4\u8f83\u4e0d\u540c\u7c7b\u578b\u7684\u65f6\u95f4\u5c5e\u6027\u65f6\uff0c\u9700\u8981\u5c0f\u5fc3\u3002\u4f8b\u5982\uff0c\u5c06\u4e00\u4e2a\u65e5\u671f\u4e0e\u4e00\u4e2a\u65f6\u95f4\u6bd4\u8f83\uff0c\u6216\u8005\u4e00\u4e2a\u65f6\u95f4\u6233\u4e0e\u4e00\u4e2a\u95f4\u9694\u6bd4\u8f83\u3002<\/p>\n<p>\u4e3a\u4e86\u6b63\u786e\u6bd4\u8f83\u4e0d\u540c\u7c7b\u578b\u7684\u65f6\u95f4\u5c5e\u6027\uff0c\u53ef\u4ee5\u5c06\u5b83\u4eec\u8f6c\u6362\u4e3a\u76f8\u540c\u7684\u6570\u636e\u7c7b\u578b\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528 CAST() \u51fd\u6570\u5c06\u65e5\u671f\u8f6c\u6362\u4e3a\u65f6\u95f4\u6233\uff0c\u6216\u8005\u4f7f\u7528 EXTRACT() \u51fd\u6570\u5c06\u65f6\u95f4\u95f4\u9694\u8f6c\u6362\u4e3a\u79d2\u6570\u3002<\/p>\n<p><strong>\u5904\u7406 NULL \u503c<\/strong><\/p>\n<p>\u6bd4\u8f83\u65f6\u95f4\u5c5e\u6027\u65f6\uff0c\u9700\u8981\u8003\u8651 NULL \u503c\u3002NULL \u503c\u8868\u793a\u7f3a\u5c11\u503c\u3002<\/p>\n<p>\u5f53\u6bd4\u8f83\u65f6\u95f4\u5c5e\u6027\u5305\u542b NULL \u503c\u65f6\uff0c\u7ed3\u679c\u53ef\u80fd\u4e3a NULL\u3002\u8fd9\u662f\u56e0\u4e3a NULL \u503c\u4e0d\u88ab\u8ba4\u4e3a\u7b49\u4e8e\u6216\u4e0d\u7b49\u4e8e\u4efb\u4f55\u5176\u4ed6\u503c\u3002<\/p>\n<p>\u8981\u907f\u514d NULL \u503c\u5bfc\u81f4\u7684\u610f\u5916\u7ed3\u679c\uff0c\u53ef\u4ee5\u5728\u6bd4\u8f83\u4e4b\u524d\u4f7f\u7528 IS NULL \u548c IS NOT NULL \u8fd0\u7b97\u7b26\u68c0\u67e5 NULL \u503c\u3002<\/p>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u6bd4\u8f83 SQL \u4e2d\u65f6\u95f4\u5c5e\u6027\u7684\u793a\u4f8b\uff1a<\/p>\n<pre>SELECT * FROM orders WHERE order_date = '2023-03-08';\nSELECT * FROM events WHERE event_time &lt; '12:00:00';\nSELECT * FROM payments WHERE payment_timestamp &gt;= CAST('2023-03-08 12:00:00' AS TIMESTAMP);\nSELECT * FROM intervals WHERE interval_duration &gt; EXTRACT(SECOND FROM INTERVAL '1 hour');<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fsql\u65f6\u95f4\u5c5e\u6027\u600e\u4e48\u6bd4\u5927\u5c0f\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\u6bd4\u8f83\u65f6\u95f4\u5c5e\u6027\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8fd0\u7b97\u7b26\uff1a=\u3001\u3001\u3001=\uff0c\u9700\u8981\u5c0f\u5fc3\u6bd4\u8f83\u4e0d\u540c\u7c7b\u578b\u7684\u65f6\u95f4\u5c5e\u6027\u3002\u6bd4\u8f83\u65f6\u9700\u8003\u8651 null \u503c\uff0c\u53ef\u4ee5\u4f7f\u7528 is null \u548c is not null \u8fd0\u7b97\u7b26\u68c0\u67e5 null \u503c\u3002 \u5982\u4f55\u6bd4\u8f83 SQL \u4e2d\u7684\u65f6\u95f4\u5c5e\u6027 \u5728 SQL \u4e2d\u6bd4\u8f83\u65f6\u95f4\u5c5e\u6027\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528\u591a\u79cd\u8fd0\u7b97\u7b26\uff0c\u5305\u62ec\uff1a =\uff1a\u68c0\u67e5\u65f6\u95f4\u5c5e\u6027\u662f\u5426\u76f8\u7b49\u3002 \uff1a\u68c0\u67e5\u65f6\u95f4\u5c5e\u6027\u662f\u5426\u4e0d\u76f8\u7b49\u3002 \uff1a\u68c0\u67e5\u65f6\u95f4\u5c5e\u6027\u662f\u5426\u65e9\u4e8e\u53e6\u4e00\u4e2a\u65f6\u95f4\u5c5e\u6027\u3002 &gt;\uff1a\u68c0\u67e5\u65f6\u95f4\u5c5e\u6027\u662f\u5426\u665a\u4e8e\u53e6\u4e00\u4e2a\u65f6\u95f4\u5c5e\u6027\u3002 \uff1a\u68c0\u67e5\u65f6\u95f4\u5c5e\u6027\u662f\u5426\u65e9\u4e8e\u6216\u7b49\u4e8e\u53e6\u4e00\u4e2a\u65f6\u95f4\u5c5e\u6027\u3002 &gt;=\uff1a\u68c0\u67e5\u65f6\u95f4\u5c5e\u6027\u662f\u5426\u665a\u4e8e\u6216\u7b49\u4e8e\u53e6\u4e00\u4e2a\u65f6\u95f4\u5c5e\u6027\u3002 \u6bd4\u8f83\u4e0d\u540c\u7c7b\u578b\u7684\u65f6\u95f4\u5c5e\u6027 \u6bd4\u8f83\u4e0d\u540c\u7c7b\u578b\u7684\u65f6\u95f4\u5c5e\u6027\u65f6\uff0c\u9700\u8981\u5c0f\u5fc3\u3002\u4f8b\u5982\uff0c\u5c06\u4e00\u4e2a\u65e5\u671f\u4e0e\u4e00\u4e2a\u65f6\u95f4\u6bd4\u8f83\uff0c\u6216\u8005\u4e00\u4e2a\u65f6\u95f4\u6233\u4e0e\u4e00\u4e2a\u95f4\u9694\u6bd4\u8f83\u3002 \u4e3a\u4e86\u6b63\u786e\u6bd4\u8f83\u4e0d\u540c\u7c7b\u578b\u7684\u65f6\u95f4\u5c5e\u6027\uff0c\u53ef\u4ee5\u5c06\u5b83\u4eec\u8f6c\u6362\u4e3a\u76f8\u540c\u7684\u6570\u636e\u7c7b\u578b\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u4f7f\u7528 CAST() \u51fd\u6570\u5c06\u65e5\u671f\u8f6c\u6362\u4e3a\u65f6\u95f4\u6233\uff0c\u6216\u8005\u4f7f\u7528 EXTRACT() \u51fd\u6570\u5c06\u65f6\u95f4\u95f4\u9694\u8f6c\u6362\u4e3a\u79d2\u6570\u3002 \u5904\u7406 NULL \u503c \u6bd4\u8f83\u65f6\u95f4\u5c5e\u6027\u65f6\uff0c\u9700\u8981\u8003\u8651 NULL \u503c\u3002NULL \u503c\u8868\u793a\u7f3a\u5c11\u503c\u3002 \u5f53\u6bd4\u8f83\u65f6\u95f4\u5c5e\u6027\u5305\u542b NULL \u503c\u65f6\uff0c\u7ed3\u679c\u53ef\u80fd\u4e3a NULL\u3002\u8fd9\u662f\u56e0\u4e3a NULL \u503c\u4e0d\u88ab\u8ba4\u4e3a\u7b49\u4e8e\u6216\u4e0d\u7b49\u4e8e\u4efb\u4f55\u5176\u4ed6\u503c\u3002 \u8981\u907f\u514d NULL \u503c\u5bfc\u81f4\u7684\u610f\u5916\u7ed3\u679c\uff0c\u53ef\u4ee5\u5728\u6bd4\u8f83\u4e4b\u524d\u4f7f\u7528 IS NULL \u548c IS NOT NULL [&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-5903","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5903","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=5903"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5903\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5903"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5903"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}