{"id":6437,"date":"2024-11-14T08:02:29","date_gmt":"2024-11-14T00:02:29","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6437\/"},"modified":"2024-11-14T08:02:29","modified_gmt":"2024-11-14T00:02:29","slug":"mysql%e6%9d%a1%e4%bb%b6%e6%9f%a5%e8%af%a2%e8%af%ad%e5%8f%a5","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6437\/","title":{"rendered":"mysql\u6761\u4ef6\u67e5\u8be2\u8bed\u53e5"},"content":{"rendered":"<blockquote><p>\n  mysql\u6761\u4ef6\u67e5\u8be2\u8bed\u53e5\u7528\u4e8e\u6839\u636e\u7279\u5b9a\u6761\u4ef6\u68c0\u7d22\u6570\u636e\uff0c\u4f7f\u7528where\u5b50\u53e5\u6307\u5b9a\u6761\u4ef6\uff0c\u652f\u6301\u591a\u79cd\u6761\u4ef6\u7c7b\u578b\uff0c\u5305\u62ec\u6bd4\u8f83\u8fd0\u7b97\u7b26\u3001\u903b\u8f91\u8fd0\u7b97\u7b26\u3001null\u68c0\u67e5\u3001\u5b57\u7b26\u4e32\u5339\u914d\u7b49\u3002\u9ad8\u7ea7\u6761\u4ef6\u5305\u62ec\u5b50\u67e5\u8be2\u3001\u8fde\u63a5\u3001\u5206\u7ec4\u548c\u6392\u5e8f\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202408\/02\/2024080220255986838.jpg\" class=\"aligncenter\" title=\"mysql\u6761\u4ef6\u67e5\u8be2\u8bed\u53e5\u63d2\u56fe\" alt=\"mysql\u6761\u4ef6\u67e5\u8be2\u8bed\u53e5\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL\u6761\u4ef6\u67e5\u8be2\u8bed\u53e5<\/strong><\/p>\n<p>\u6761\u4ef6\u67e5\u8be2\u8bed\u53e5\u7528\u4e8e\u4eceMySQL\u6570\u636e\u5e93\u4e2d\u68c0\u7d22\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u7684\u884c\u3002\u5b83\u4f7f\u7528WHERE\u5b50\u53e5\u6307\u5b9a\u6761\u4ef6\uff0c\u8be5\u5b50\u53e5\u9075\u5faa\u4ee5\u4e0b\u8bed\u6cd5\uff1a<\/p>\n<pre>SELECT \u5217\u540d\nFROM \u8868\u540d\nWHERE \u6761\u4ef6<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6761\u4ef6\u7684\u7c7b\u578b<\/strong><\/p>\n<p>MySQL\u652f\u6301\u591a\u79cd\u6761\u4ef6\u7c7b\u578b\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li> <strong>\u6bd4\u8f83\u8fd0\u7b97\u7b26\uff1a<\/strong>=\u3001!=\u3001&gt;\u3001=\u3001<\/li>\n<li> <strong>\u903b\u8f91\u8fd0\u7b97\u7b26\uff1a<\/strong>AND\u3001OR\u3001NOT<\/li>\n<li> <strong>NULL\u68c0\u67e5\uff1a<\/strong>IS NULL\u3001IS NOT NULL<\/li>\n<li> <strong>\u5b57\u7b26\u4e32\u5339\u914d\uff1a<\/strong>LIKE\u3001NOT LIKE<\/li>\n<\/ul>\n<p><strong>\u4f7f\u7528\u793a\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u662f\u4e00\u4e9b\u4f7f\u7528\u6761\u4ef6\u67e5\u8be2\u8bed\u53e5\u7684\u793a\u4f8b\uff1a<\/p>\n<ul>\n<li>\n<p><strong>\u67e5\u627e\u5177\u6709\u7279\u5b9aID\u7684\u5ba2\u6237\uff1a<\/strong><\/p>\n<pre>SELECT *\nFROM customers\nWHERE id = 123;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p><strong>\u67e5\u627e\u8ba2\u5355\u91d1\u989d\u5927\u4e8e500\u5143\u7684\u8ba2\u5355\uff1a<\/strong><\/p>\n<pre>SELECT *\nFROM orders\nWHERE amount &gt; 500;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p><strong>\u67e5\u627e\u5305\u542b\u201cJohn\u201d\u7684\u5ba2\u6237\u59d3\u540d\uff1a<\/strong><\/p>\n<pre>SELECT *\nFROM customers\nWHERE name LIKE '%John%';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p><strong>\u67e5\u627e\u5df2\u53d6\u6d88\u7684\u8ba2\u5355\uff1a<\/strong><\/p>\n<pre>SELECT *\nFROM orders\nWHERE status = 'cancelled';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p><strong>\u67e5\u627e\u5177\u6709\u6307\u5b9aID\u6216\u72b6\u6001\u7684\u5ba2\u6237\uff1a<\/strong><\/p>\n<pre>SELECT *\nFROM customers\nWHERE id = 123 OR status = 'active';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ul>\n<p><strong>\u9ad8\u7ea7\u6761\u4ef6<\/strong><\/p>\n<p>MySQL\u8fd8\u652f\u6301\u9ad8\u7ea7\u6761\u4ef6\uff0c\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li> <strong>\u5b50\u67e5\u8be2\uff1a<\/strong>\u5728\u53e6\u4e00\u4e2a\u67e5\u8be2\u7684\u7ed3\u679c\u4e2d\u67e5\u627e\u5339\u914d\u9879<\/li>\n<li> <strong>\u8fde\u63a5\uff1a<\/strong>\u4f7f\u7528JOIN\u5b50\u53e5\u8fde\u63a5\u591a\u4e2a\u8868<\/li>\n<li> <strong>\u5206\u7ec4\u548c\u6392\u5e8f\uff1a<\/strong>\u5bf9\u7ed3\u679c\u8fdb\u884c\u5206\u7ec4\u548c\u6392\u5e8f<\/li>\n<\/ul>\n<p>\u901a\u8fc7\u4f7f\u7528\u8fd9\u4e9b\u9ad8\u7ea7\u529f\u80fd\uff0c\u53ef\u4ee5\u521b\u5efa\u590d\u6742\u7684\u67e5\u8be2\u4ee5\u4eceMySQL\u6570\u636e\u5e93\u4e2d\u68c0\u7d22\u6240\u9700\u7684\u6570\u636e\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u6761\u4ef6\u67e5\u8be2\u8bed\u53e5\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>mysql\u6761\u4ef6\u67e5\u8be2\u8bed\u53e5\u7528\u4e8e\u6839\u636e\u7279\u5b9a\u6761\u4ef6\u68c0\u7d22\u6570\u636e\uff0c\u4f7f\u7528where\u5b50\u53e5\u6307\u5b9a\u6761\u4ef6\uff0c\u652f\u6301\u591a\u79cd\u6761\u4ef6\u7c7b\u578b\uff0c\u5305\u62ec\u6bd4\u8f83\u8fd0\u7b97\u7b26\u3001\u903b\u8f91\u8fd0\u7b97\u7b26\u3001null\u68c0\u67e5\u3001\u5b57\u7b26\u4e32\u5339\u914d\u7b49\u3002\u9ad8\u7ea7\u6761\u4ef6\u5305\u62ec\u5b50\u67e5\u8be2\u3001\u8fde\u63a5\u3001\u5206\u7ec4\u548c\u6392\u5e8f\u3002 MySQL\u6761\u4ef6\u67e5\u8be2\u8bed\u53e5 \u6761\u4ef6\u67e5\u8be2\u8bed\u53e5\u7528\u4e8e\u4eceMySQL\u6570\u636e\u5e93\u4e2d\u68c0\u7d22\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\u7684\u884c\u3002\u5b83\u4f7f\u7528WHERE\u5b50\u53e5\u6307\u5b9a\u6761\u4ef6\uff0c\u8be5\u5b50\u53e5\u9075\u5faa\u4ee5\u4e0b\u8bed\u6cd5\uff1a SELECT \u5217\u540d FROM \u8868\u540d WHERE \u6761\u4ef6 \u767b\u5f55\u540e\u590d\u5236 \u6761\u4ef6\u7684\u7c7b\u578b MySQL\u652f\u6301\u591a\u79cd\u6761\u4ef6\u7c7b\u578b\uff0c\u5305\u62ec\uff1a \u6bd4\u8f83\u8fd0\u7b97\u7b26\uff1a=\u3001!=\u3001&gt;\u3001=\u3001 \u903b\u8f91\u8fd0\u7b97\u7b26\uff1aAND\u3001OR\u3001NOT NULL\u68c0\u67e5\uff1aIS NULL\u3001IS NOT NULL \u5b57\u7b26\u4e32\u5339\u914d\uff1aLIKE\u3001NOT LIKE \u4f7f\u7528\u793a\u4f8b \u4ee5\u4e0b\u662f\u4e00\u4e9b\u4f7f\u7528\u6761\u4ef6\u67e5\u8be2\u8bed\u53e5\u7684\u793a\u4f8b\uff1a \u67e5\u627e\u5177\u6709\u7279\u5b9aID\u7684\u5ba2\u6237\uff1a SELECT * FROM customers WHERE id = 123; \u767b\u5f55\u540e\u590d\u5236 \u67e5\u627e\u8ba2\u5355\u91d1\u989d\u5927\u4e8e500\u5143\u7684\u8ba2\u5355\uff1a SELECT * FROM orders WHERE amount &gt; 500; \u767b\u5f55\u540e\u590d\u5236 \u67e5\u627e\u5305\u542b\u201cJohn\u201d\u7684\u5ba2\u6237\u59d3\u540d\uff1a SELECT * FROM customers WHERE name LIKE &#8216;%John%&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u67e5\u627e\u5df2\u53d6\u6d88\u7684\u8ba2\u5355\uff1a SELECT * [&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-6437","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6437","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=6437"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6437\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6437"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6437"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6437"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}