{"id":5195,"date":"2024-11-14T12:35:08","date_gmt":"2024-11-14T04:35:08","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5195\/"},"modified":"2024-11-14T12:35:08","modified_gmt":"2024-11-14T04:35:08","slug":"sql%e4%b8%ad%e5%a4%9a%e4%b8%aalike%e7%9a%84%e7%94%a8%e6%b3%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5195\/","title":{"rendered":"sql\u4e2d\u591a\u4e2alike\u7684\u7528\u6cd5"},"content":{"rendered":"<blockquote><p>\n  like \u8fd0\u7b97\u7b26\u7528\u4e8e\u6bd4\u8f83\u5b57\u7b26\u4e32\u662f\u5426\u4e0e\u7279\u5b9a\u6a21\u5f0f\u5339\u914d\uff0c\u53ef\u7528\u7279\u6b8a\u5b57\u7b26\u5b9a\u4e49\u6a21\u5f0f\uff1a1. \u767e\u5206\u53f7 (%) \u5339\u914d\u96f6\u4e2a\u6216\u591a\u4e2a\u5b57\u7b26\uff1b2. \u4e0b\u5212\u7ebf (_) \u5339\u914d\u5355\u4e2a\u5b57\u7b26\u3002\u652f\u6301\u4f7f\u7528\u591a\u4e2a like \u8fd0\u7b97\u7b26\u67e5\u627e\u6ee1\u8db3\u591a\u4e2a\u6761\u4ef6\u7684\u5b57\u7b26\u4e32\u3002\u4f7f\u7528 and \u8fd0\u7b97\u7b26\u8fde\u63a5\u591a\u4e2a like \u8868\u8fbe\u5f0f\uff0c\u5219\u6240\u6709\u6761\u4ef6\u90fd\u5fc5\u987b\u4e3a\u771f\u624d\u80fd\u5339\u914d\uff1b\u4f7f\u7528 or \u8fd0\u7b97\u7b26\u65f6\uff0c\u4efb\u4f55\u6761\u4ef6\u4e3a\u771f\u5373\u53ef\u5339\u914d\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/24\/2024052419541861814.jpg\" class=\"aligncenter\" title=\"sql\u4e2d\u591a\u4e2alike\u7684\u7528\u6cd5\u63d2\u56fe\" alt=\"sql\u4e2d\u591a\u4e2alike\u7684\u7528\u6cd5\u63d2\u56fe\" \/><\/p>\n<p><strong>SQL \u4e2d LIKE \u8fd0\u7b97\u7b26\u7684\u7528\u6cd5<\/strong><\/p>\n<p><strong>\u4f55\u8c13 LIKE \u8fd0\u7b97\u7b26\uff1f<\/strong><\/p>\n<p>LIKE \u8fd0\u7b97\u7b26\u7528\u4e8e\u6bd4\u8f83\u5b57\u7b26\u4e32\u662f\u5426\u4e0e\u7279\u5b9a\u7684\u6a21\u5f0f\u5339\u914d\u3002\u8be5\u6a21\u5f0f\u53ef\u4ee5\u5305\u542b\u7279\u6b8a\u5b57\u7b26\uff0c\u5305\u62ec\uff1a<\/p>\n<ul>\n<li>\u767e\u5206\u53f7 (%)\uff1a\u5339\u914d\u96f6\u4e2a\u6216\u591a\u4e2a\u5b57\u7b26\u3002<\/li>\n<li>\u4e0b\u5212\u7ebf (_)\uff1a\u5339\u914d\u5355\u4e2a\u5b57\u7b26\u3002<\/li>\n<\/ul>\n<p><strong>\u591a\u4e2a LIKE \u8fd0\u7b97\u7b26\u7684\u7528\u6cd5<\/strong><\/p>\n<p>SQL \u4e2d\u5141\u8bb8\u5728\u67e5\u8be2\u4e2d\u4f7f\u7528\u591a\u4e2a LIKE \u8fd0\u7b97\u7b26\u3002\u8fd9\u53ef\u7528\u4e8e\u67e5\u627e\u6ee1\u8db3\u591a\u4e2a\u6761\u4ef6\u7684\u5b57\u7b26\u4e32\u3002<\/p>\n<p>\u8bed\u6cd5\uff1a<\/p>\n<pre>SELECT column_name\nFROM table_name\nWHERE column_name LIKE pattern1\nAND column_name LIKE pattern2\n...<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p><strong>AND \u548c OR \u8fd0\u7b97\u7b26<\/strong><\/p>\n<ul>\n<li> <strong>AND\uff1a<\/strong>\u4f7f\u7528 AND \u8fd0\u7b97\u7b26\u8fde\u63a5\u591a\u4e2a LIKE \u8868\u8fbe\u5f0f\uff0c\u8868\u793a\u6240\u6709\u6761\u4ef6\u90fd\u5fc5\u987b\u4e3a\u771f\u624d\u80fd\u5339\u914d\u3002<\/li>\n<li> <strong>OR\uff1a<\/strong>\u4f7f\u7528 OR \u8fd0\u7b97\u7b26\u8fde\u63a5\u591a\u4e2a LIKE \u8868\u8fbe\u5f0f\uff0c\u8868\u793a\u4efb\u4f55\u6761\u4ef6\u4e3a\u771f\u5373\u53ef\u5339\u914d\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b<\/strong><\/p>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u67e5\u627e\u5305\u542b &#8220;John&#8221; \u548c &#8220;Smith&#8221; \u5b57\u7b26\u4e32\u7684\u8bb0\u5f55\uff1a<\/p>\n<pre>SELECT *\nFROM employee\nWHERE first_name LIKE '%John%'\nAND last_name LIKE '%Smith%'<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0b\u793a\u4f8b\u67e5\u627e\u5305\u542b &#8220;John&#8221; \u6216\u4ee5 &#8220;S&#8221; \u5f00\u5934\u7684\u8bb0\u5f55\uff1a<\/p>\n<pre>SELECT *\nFROM employee\nWHERE first_name LIKE '%John%'\nOR last_name LIKE 'S%'<\/pre>\n<p>  \u767b\u5f55\u540e\u590d\u5236   <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fsql\u4e2d\u591a\u4e2alike\u7684\u7528\u6cd5\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\u7528\u4e8e\u6bd4\u8f83\u5b57\u7b26\u4e32\u662f\u5426\u4e0e\u7279\u5b9a\u6a21\u5f0f\u5339\u914d\uff0c\u53ef\u7528\u7279\u6b8a\u5b57\u7b26\u5b9a\u4e49\u6a21\u5f0f\uff1a1. \u767e\u5206\u53f7 (%) \u5339\u914d\u96f6\u4e2a\u6216\u591a\u4e2a\u5b57\u7b26\uff1b2. \u4e0b\u5212\u7ebf (_) \u5339\u914d\u5355\u4e2a\u5b57\u7b26\u3002\u652f\u6301\u4f7f\u7528\u591a\u4e2a like \u8fd0\u7b97\u7b26\u67e5\u627e\u6ee1\u8db3\u591a\u4e2a\u6761\u4ef6\u7684\u5b57\u7b26\u4e32\u3002\u4f7f\u7528 and \u8fd0\u7b97\u7b26\u8fde\u63a5\u591a\u4e2a like \u8868\u8fbe\u5f0f\uff0c\u5219\u6240\u6709\u6761\u4ef6\u90fd\u5fc5\u987b\u4e3a\u771f\u624d\u80fd\u5339\u914d\uff1b\u4f7f\u7528 or \u8fd0\u7b97\u7b26\u65f6\uff0c\u4efb\u4f55\u6761\u4ef6\u4e3a\u771f\u5373\u53ef\u5339\u914d\u3002 SQL \u4e2d LIKE \u8fd0\u7b97\u7b26\u7684\u7528\u6cd5 \u4f55\u8c13 LIKE \u8fd0\u7b97\u7b26\uff1f LIKE \u8fd0\u7b97\u7b26\u7528\u4e8e\u6bd4\u8f83\u5b57\u7b26\u4e32\u662f\u5426\u4e0e\u7279\u5b9a\u7684\u6a21\u5f0f\u5339\u914d\u3002\u8be5\u6a21\u5f0f\u53ef\u4ee5\u5305\u542b\u7279\u6b8a\u5b57\u7b26\uff0c\u5305\u62ec\uff1a \u767e\u5206\u53f7 (%)\uff1a\u5339\u914d\u96f6\u4e2a\u6216\u591a\u4e2a\u5b57\u7b26\u3002 \u4e0b\u5212\u7ebf (_)\uff1a\u5339\u914d\u5355\u4e2a\u5b57\u7b26\u3002 \u591a\u4e2a LIKE \u8fd0\u7b97\u7b26\u7684\u7528\u6cd5 SQL \u4e2d\u5141\u8bb8\u5728\u67e5\u8be2\u4e2d\u4f7f\u7528\u591a\u4e2a LIKE \u8fd0\u7b97\u7b26\u3002\u8fd9\u53ef\u7528\u4e8e\u67e5\u627e\u6ee1\u8db3\u591a\u4e2a\u6761\u4ef6\u7684\u5b57\u7b26\u4e32\u3002 \u8bed\u6cd5\uff1a SELECT column_name FROM table_name WHERE column_name LIKE pattern1 AND column_name LIKE pattern2 &#8230; \u767b\u5f55\u540e\u590d\u5236 AND \u548c OR \u8fd0\u7b97\u7b26 [&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-5195","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5195","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=5195"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5195\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5195"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5195"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5195"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}