{"id":75824,"date":"2024-10-16T01:32:14","date_gmt":"2024-10-15T17:32:14","guid":{"rendered":"https:\/\/server.hk\/cnblog\/75824\/"},"modified":"2024-10-16T01:32:14","modified_gmt":"2024-10-15T17:32:14","slug":"mysql-%e6%9f%a5%e8%a9%a2%e4%b8%ad%e7%9a%84%e9%9d%9e%e7%a9%ba%e5%95%8f%e9%a1%8c","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/75824\/","title":{"rendered":"MySQL \u67e5\u8a62\u4e2d\u7684\u975e\u7a7a\u554f\u984c"},"content":{"rendered":"<h1 id=\"mysql-%e6%9f%a5%e8%a9%a2%e4%b8%ad%e7%9a%84%e9%9d%9e%e7%a9%ba%e5%95%8f%e9%a1%8c-ChyhqtbYFD\">MySQL \u67e5\u8a62\u4e2d\u7684\u975e\u7a7a\u554f\u984c<\/h1>\n<p>\u5728\u4f7f\u7528 MySQL \u6578\u64da\u5eab\u6642\uff0c\u67e5\u8a62\u7684\u6e96\u78ba\u6027\u548c\u6548\u7387\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u7279\u5225\u662f\u5728\u8655\u7406\u5927\u91cf\u6578\u64da\u6642\uff0c\u5982\u4f55\u6b63\u78ba\u5730\u7be9\u9078\u51fa\u975e\u7a7a\u503c\uff08NOT NULL\uff09\u6210\u70ba\u4e86\u958b\u767c\u8005\u9700\u8981\u9762\u5c0d\u7684\u4e00\u500b\u91cd\u8981\u554f\u984c\u3002\u672c\u6587\u5c07\u6df1\u5165\u63a2\u8a0e MySQL \u4e2d\u7684\u975e\u7a7a\u554f\u984c\uff0c\u5305\u62ec\u5176\u5b9a\u7fa9\u3001\u67e5\u8a62\u65b9\u6cd5\u53ca\u6700\u4f73\u5be6\u8e10\u3002<\/p>\n<h2 id=\"%e9%9d%9e%e7%a9%ba%e5%80%bc%e7%9a%84%e5%ae%9a%e7%be%a9-ChyhqtbYFD\">\u975e\u7a7a\u503c\u7684\u5b9a\u7fa9<\/h2>\n<p>\u5728 MySQL \u4e2d\uff0c\u975e\u7a7a\u503c\u662f\u6307\u4e0d\u7b49\u65bc NULL \u7684\u6578\u64da\u3002NULL \u662f\u4e00\u500b\u7279\u6b8a\u7684\u6a19\u8a18\uff0c\u7528\u4f86\u8868\u793a\u6578\u64da\u7684\u7f3a\u5931\u6216\u672a\u77e5\u3002\u7576\u4e00\u500b\u5b57\u6bb5\u88ab\u5b9a\u7fa9\u70ba NOT NULL \u6642\uff0c\u9019\u610f\u5473\u8457\u8a72\u5b57\u6bb5\u5fc5\u9808\u6709\u4e00\u500b\u6709\u6548\u7684\u503c\uff0c\u4e0d\u80fd\u70ba NULL\u3002<\/p>\n<h2 id=\"%e6%9f%a5%e8%a9%a2%e9%9d%9e%e7%a9%ba%e5%80%bc%e7%9a%84%e6%96%b9%e6%b3%95-ChyhqtbYFD\">\u67e5\u8a62\u975e\u7a7a\u503c\u7684\u65b9\u6cd5<\/h2>\n<p>\u5728 MySQL \u4e2d\uff0c\u67e5\u8a62\u975e\u7a7a\u503c\u7684\u6700\u5e38\u7528\u65b9\u6cd5\u662f\u4f7f\u7528 WHERE \u5b50\u53e5\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u898b\u7684\u67e5\u8a62\u793a\u4f8b\uff1a<\/p>\n<h3 id=\"%e5%9f%ba%e6%9c%ac%e6%9f%a5%e8%a9%a2-ChyhqtbYFD\">\u57fa\u672c\u67e5\u8a62<\/h3>\n<pre><code>SELECT * FROM \u8868\u540d WHERE \u5b57\u6bb5\u540d IS NOT NULL;<\/code><\/pre>\n<p>\u9019\u689d\u67e5\u8a62\u5c07\u8fd4\u56de\u6240\u6709\u5728\u6307\u5b9a\u5b57\u6bb5\u4e2d\u4e0d\u70ba NULL \u7684\u8a18\u9304\u3002<\/p>\n<h3 id=\"%e7%b5%90%e5%90%88%e5%85%b6%e4%bb%96%e6%a2%9d%e4%bb%b6-ChyhqtbYFD\">\u7d50\u5408\u5176\u4ed6\u689d\u4ef6<\/h3>\n<p>\u6709\u6642\u5019\uff0c\u6211\u5011\u9700\u8981\u5728\u67e5\u8a62\u4e2d\u7d50\u5408\u5176\u4ed6\u689d\u4ef6\u3002\u4f8b\u5982\uff0c\u67e5\u8a62\u67d0\u500b\u5b57\u6bb5\u4e0d\u70ba NULL \u4e14\u53e6\u4e00\u500b\u5b57\u6bb5\u7b49\u65bc\u7279\u5b9a\u503c\u7684\u8a18\u9304\uff1a<\/p>\n<pre><code>SELECT * FROM \u8868\u540d WHERE \u5b57\u6bb5\u540d IS NOT NULL AND \u53e6\u4e00\u5b57\u6bb5\u540d = '\u7279\u5b9a\u503c';<\/code><\/pre>\n<h3 id=\"%e4%bd%bf%e7%94%a8-count-%e5%87%bd%e6%95%b8-ChyhqtbYFD\">\u4f7f\u7528 COUNT \u51fd\u6578<\/h3>\n<p>\u5982\u679c\u6211\u5011\u60f3\u8981\u8a08\u7b97\u67d0\u500b\u5b57\u6bb5\u4e2d\u975e\u7a7a\u503c\u7684\u6578\u91cf\uff0c\u53ef\u4ee5\u4f7f\u7528 COUNT \u51fd\u6578\uff1a<\/p>\n<pre><code>SELECT COUNT(\u5b57\u6bb5\u540d) FROM \u8868\u540d WHERE \u5b57\u6bb5\u540d IS NOT NULL;<\/code><\/pre>\n<p>\u9019\u689d\u67e5\u8a62\u5c07\u8fd4\u56de\u6307\u5b9a\u5b57\u6bb5\u4e2d\u975e\u7a7a\u503c\u7684\u7e3d\u6578\u3002<\/p>\n<h2 id=\"%e6%9c%80%e4%bd%b3%e5%af%a6%e8%b8%90-ChyhqtbYFD\">\u6700\u4f73\u5be6\u8e10<\/h2>\n<p>\u5728\u9032\u884c MySQL \u67e5\u8a62\u6642\uff0c\u9075\u5faa\u4e00\u4e9b\u6700\u4f73\u5be6\u8e10\u53ef\u4ee5\u63d0\u9ad8\u67e5\u8a62\u7684\u6548\u7387\u548c\u6e96\u78ba\u6027\uff1a<\/p>\n<ul>\n<li><strong>\u5408\u7406\u8a2d\u8a08\u6578\u64da\u8868\uff1a<\/strong>\u5728\u8a2d\u8a08\u6578\u64da\u8868\u6642\uff0c\u6839\u64da\u696d\u52d9\u9700\u6c42\u5408\u7406\u8a2d\u7f6e\u5b57\u6bb5\u7684 NULL \u548c NOT NULL \u5c6c\u6027\uff0c\u907f\u514d\u4e0d\u5fc5\u8981\u7684 NULL \u503c\u3002<\/li>\n<li><strong>\u4f7f\u7528\u7d22\u5f15\uff1a<\/strong>\u5c0d\u65bc\u7d93\u5e38\u67e5\u8a62\u7684\u5b57\u6bb5\uff0c\u8003\u616e\u4f7f\u7528\u7d22\u5f15\u4f86\u63d0\u9ad8\u67e5\u8a62\u6027\u80fd\u3002<\/li>\n<li><strong>\u907f\u514d\u4f7f\u7528 SELECT *\uff1a<\/strong>\u5728\u67e5\u8a62\u6642\uff0c\u76e1\u91cf\u6307\u5b9a\u9700\u8981\u7684\u5b57\u6bb5\uff0c\u9019\u6a23\u53ef\u4ee5\u6e1b\u5c11\u6578\u64da\u50b3\u8f38\u91cf\uff0c\u63d0\u9ad8\u67e5\u8a62\u901f\u5ea6\u3002<\/li>\n<li><strong>\u5b9a\u671f\u6e05\u7406\u6578\u64da\uff1a<\/strong>\u5b9a\u671f\u6aa2\u67e5\u548c\u6e05\u7406\u6578\u64da\u5eab\u4e2d\u7684 NULL \u503c\uff0c\u4fdd\u6301\u6578\u64da\u7684\u6574\u6f54\u6027\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-ChyhqtbYFD\">\u7d50\u8ad6<\/h2>\n<p>\u5728 MySQL \u67e5\u8a62\u4e2d\uff0c\u6b63\u78ba\u8655\u7406\u975e\u7a7a\u554f\u984c\u662f\u78ba\u4fdd\u6578\u64da\u6e96\u78ba\u6027\u548c\u67e5\u8a62\u6548\u7387\u7684\u95dc\u9375\u3002\u901a\u904e\u5408\u7406\u7684\u67e5\u8a62\u65b9\u6cd5\u548c\u6700\u4f73\u5be6\u8e10\uff0c\u958b\u767c\u8005\u53ef\u4ee5\u6709\u6548\u5730\u7ba1\u7406\u6578\u64da\u5eab\u4e2d\u7684\u975e\u7a7a\u503c\uff0c\u5f9e\u800c\u63d0\u5347\u6574\u9ad4\u7cfb\u7d71\u7684\u6027\u80fd\u3002<\/p>\n<p>\u5982\u9700\u4e86\u89e3\u66f4\u591a\u95dc\u65bc <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u548c\u6578\u64da\u5eab\u7ba1\u7406\u7684\u8cc7\u8a0a\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3MySQL\u67e5\u8a62\u4e2d\u7684\u975e\u7a7a\u554f\u984c\uff0c\u638c\u63e1\u5982\u4f55\u8655\u7406NULL\u503c\uff0c\u63d0\u5347\u6578\u64da\u67e5\u8a62\u7684\u6e96\u78ba\u6027\u8207\u6548\u7387\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-75824","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/75824","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=75824"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/75824\/revisions"}],"predecessor-version":[{"id":75825,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/75824\/revisions\/75825"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=75824"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=75824"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=75824"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}