{"id":5533,"date":"2024-11-14T12:56:43","date_gmt":"2024-11-14T04:56:43","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5533\/"},"modified":"2024-11-14T12:56:43","modified_gmt":"2024-11-14T04:56:43","slug":"mysql%e7%9a%84like%e6%80%8e%e4%b9%88%e7%94%a8","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5533\/","title":{"rendered":"mysql\u7684like\u600e\u4e48\u7528"},"content":{"rendered":"<blockquote><p>\n  like \u8fd0\u7b97\u7b26\u5728 mysql \u4e2d\u7528\u4e8e\u6a21\u5f0f\u5339\u914d\uff0c\u652f\u6301\u901a\u914d\u7b26\uff1a1) %\uff1a\u5339\u914d\u96f6\u4e2a\u6216\u591a\u4e2a\u5b57\u7b26\uff1b2) _\uff1a\u5339\u914d\u5355\u4e2a\u5b57\u7b26\uff1b3) [list]\uff1a\u5339\u914d\u62ec\u53f7\u5185\u5217\u51fa\u7684\u4efb\u4f55\u5b57\u7b26\uff1b4) 1\uff1a\u5339\u914d\u4e0d\u5728\u62ec\u53f7\u5185\u5217\u51fa\u7684\u4efb\u4f55\u5b57\u7b26\u3002\u5b83\u652f\u6301\u7d22\u5f15\uff0c\u63d0\u9ad8\u67e5\u8be2\u6548\u7387\uff0c\u4f46\u533a\u5206\u5927\u5c0f\u5199\uff0c\u53ef\u4ee5\u4f7f\u7528\u8f6c\u4e49\u5b57\u7b26\u3002list \u21a9\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/29\/2024052908242432142.jpg\" class=\"aligncenter\" title=\"mysql\u7684like\u600e\u4e48\u7528\u63d2\u56fe\" alt=\"mysql\u7684like\u600e\u4e48\u7528\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u4e2d\u7684 LIKE \u8fd0\u7b97\u7b26<\/strong><\/p>\n<p>LIKE \u8fd0\u7b97\u7b26\u7528\u4e8e\u5728 MySQL \u4e2d\u6267\u884c\u6a21\u5f0f\u5339\u914d\u67e5\u8be2\u3002\u5b83\u5141\u8bb8\u60a8\u4f7f\u7528\u901a\u914d\u7b26\u6765\u67e5\u627e\u4e0e\u6307\u5b9a\u6a21\u5f0f\u76f8\u5339\u914d\u7684\u6570\u636e\u3002<\/p>\n<p><strong>\u8bed\u6cd5<\/strong><\/p>\n<pre>SELECT * FROM table_name WHERE column_name LIKE 'pattern';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u901a\u914d\u7b26<\/strong><\/p>\n<p>LIKE \u8fd0\u7b97\u7b26\u652f\u6301\u4ee5\u4e0b\u901a\u914d\u7b26\uff1a<\/p>\n<ul>\n<li> <strong>%:<\/strong> \u5339\u914d\u96f6\u4e2a\u3001\u4e00\u4e2a\u6216\u591a\u4e2a\u5b57\u7b26\u3002<\/li>\n<li> <strong>_:<\/strong> \u5339\u914d\u5355\u4e2a\u5b57\u7b26\u3002<\/li>\n<li> <strong>[list]:<\/strong> \u5339\u914d\u62ec\u53f7\u5185\u5217\u51fa\u7684\u4efb\u4f55\u5b57\u7b26\u3002<\/li>\n<li> <strong><sup><\/sup>:<\/strong> \u5339\u914d\u4e0d\u5728\u62ec\u53f7\u5185\u5217\u51fa\u7684\u4efb\u4f55\u5b57\u7b26\u3002<\/li>\n<\/ul>\n<p><strong>\u7528\u6cd5<\/strong><\/p>\n<p>\u8981\u4f7f\u7528 LIKE \u8fd0\u7b97\u7b26\uff0c\u8bf7\u6307\u5b9a\u5217\u540d\u3001\u6a21\u5f0f\u548c\u901a\u914d\u7b26\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u67e5\u8be2\u67e5\u627e\u4ee5 &#8220;John&#8221; \u5f00\u5934\u7684\u6240\u6709\u59d3\u540d\uff1a<\/p>\n<pre>SELECT * FROM customers WHERE name LIKE 'John%';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8981\u5bfb\u627e\u5305\u542b &#8220;Doe&#8221; \u7684\u6240\u6709\u59d3\u540d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8be2\uff1a<\/p>\n<pre>SELECT * FROM customers WHERE name LIKE '%Doe%';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8981\u67e5\u627e\u65e2\u4e0d\u4ee5 &#8220;John&#8221; \u5f00\u5934\u4e5f\u4e0d\u5305\u542b &#8220;Doe&#8221; \u7684\u6240\u6709\u59d3\u540d\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8be2\uff1a<\/p>\n<pre>SELECT * FROM customers WHERE name NOT LIKE 'John%' AND name NOT LIKE '%Doe%';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6ce8\u610f\uff1a<\/strong><\/p>\n<ul>\n<li>LIKE \u8fd0\u7b97\u7b26\u533a\u5206\u5927\u5c0f\u5199\u3002<\/li>\n<li>\u6a21\u5f0f\u53ef\u4ee5\u5305\u542b\u8f6c\u4e49\u5b57\u7b26\uff0c\u4f8b\u5982\u53cd\u659c\u6760 ()\u3002<\/li>\n<li>LIKE \u8fd0\u7b97\u7b26\u53ef\u4ee5\u4f7f\u7528\u7d22\u5f15\uff0c\u4f7f\u5176\u5bf9\u4e8e\u5927\u578b\u6570\u636e\u96c6\u975e\u5e38\u9ad8\u6548\u3002<\/li>\n<\/ul>\n<hr>\n<ol>\n<li>list  <\/li>\n<\/ol>\n<p>\u4ee5\u4e0a\u5c31\u662f\u7684like\u600e\u4e48\u7528\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>like \u8fd0\u7b97\u7b26\u5728 mysql \u4e2d\u7528\u4e8e\u6a21\u5f0f\u5339\u914d\uff0c\u652f\u6301\u901a\u914d\u7b26\uff1a1) %\uff1a\u5339\u914d\u96f6\u4e2a\u6216\u591a\u4e2a\u5b57\u7b26\uff1b2) _\uff1a\u5339\u914d\u5355\u4e2a\u5b57\u7b26\uff1b3) [list]\uff1a\u5339\u914d\u62ec\u53f7\u5185\u5217\u51fa\u7684\u4efb\u4f55\u5b57\u7b26\uff1b4) 1\uff1a\u5339\u914d\u4e0d\u5728\u62ec\u53f7\u5185\u5217\u51fa\u7684\u4efb\u4f55\u5b57\u7b26\u3002\u5b83\u652f\u6301\u7d22\u5f15\uff0c\u63d0\u9ad8\u67e5\u8be2\u6548\u7387\uff0c\u4f46\u533a\u5206\u5927\u5c0f\u5199\uff0c\u53ef\u4ee5\u4f7f\u7528\u8f6c\u4e49\u5b57\u7b26\u3002list \u21a9 MySQL \u4e2d\u7684 LIKE \u8fd0\u7b97\u7b26 LIKE \u8fd0\u7b97\u7b26\u7528\u4e8e\u5728 MySQL \u4e2d\u6267\u884c\u6a21\u5f0f\u5339\u914d\u67e5\u8be2\u3002\u5b83\u5141\u8bb8\u60a8\u4f7f\u7528\u901a\u914d\u7b26\u6765\u67e5\u627e\u4e0e\u6307\u5b9a\u6a21\u5f0f\u76f8\u5339\u914d\u7684\u6570\u636e\u3002 \u8bed\u6cd5 SELECT * FROM table_name WHERE column_name LIKE &#8216;pattern&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u901a\u914d\u7b26 LIKE \u8fd0\u7b97\u7b26\u652f\u6301\u4ee5\u4e0b\u901a\u914d\u7b26\uff1a %: \u5339\u914d\u96f6\u4e2a\u3001\u4e00\u4e2a\u6216\u591a\u4e2a\u5b57\u7b26\u3002 _: \u5339\u914d\u5355\u4e2a\u5b57\u7b26\u3002 [list]: \u5339\u914d\u62ec\u53f7\u5185\u5217\u51fa\u7684\u4efb\u4f55\u5b57\u7b26\u3002 : \u5339\u914d\u4e0d\u5728\u62ec\u53f7\u5185\u5217\u51fa\u7684\u4efb\u4f55\u5b57\u7b26\u3002 \u7528\u6cd5 \u8981\u4f7f\u7528 LIKE \u8fd0\u7b97\u7b26\uff0c\u8bf7\u6307\u5b9a\u5217\u540d\u3001\u6a21\u5f0f\u548c\u901a\u914d\u7b26\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u67e5\u8be2\u67e5\u627e\u4ee5 &#8220;John&#8221; \u5f00\u5934\u7684\u6240\u6709\u59d3\u540d\uff1a SELECT * FROM customers WHERE name LIKE &#8216;John%&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u8981\u5bfb\u627e\u5305\u542b &#8220;Doe&#8221; [&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-5533","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5533","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=5533"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5533\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5533"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5533"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}