{"id":5192,"date":"2024-11-14T09:05:18","date_gmt":"2024-11-14T01:05:18","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5192\/"},"modified":"2024-11-14T09:05:18","modified_gmt":"2024-11-14T01:05:18","slug":"sql%e4%b8%adlike%e7%94%a8%e6%b3%95","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5192\/","title":{"rendered":"sql\u4e2dlike\u7528\u6cd5"},"content":{"rendered":"<p><strong>sql \u4e2d like \u7528\u6cd5<\/strong><\/p>\n<p>LIKE \u8fd0\u7b97\u7b26\u7528\u4e8e\u5728 SQL \u67e5\u8be2\u4e2d\u5339\u914d\u5b57\u7b26\u4e32\u6a21\u5f0f\u3002\u5b83\u5141\u8bb8\u60a8\u67e5\u627e\u4e0e\u7279\u5b9a\u6a21\u5f0f\u76f8\u5339\u914d\u6216\u4ee5\u7279\u5b9a\u6a21\u5f0f\u5f00\u5934\u7684\u503c\u3002<\/p>\n<p><strong>\u8bed\u6cd5\uff1a<\/strong><\/p>\n<pre>SELECT column_name\nFROM table_name\nWHERE column_name LIKE 'pattern';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li> <strong>column_name<\/strong> \u662f\u60a8\u8981\u641c\u7d22\u7684\u5217\u3002<\/li>\n<li> <strong>pattern<\/strong> \u662f\u60a8\u8981\u5339\u914d\u7684\u6a21\u5f0f\u3002<\/li>\n<\/ul>\n<p><strong>\u901a\u914d\u7b26\uff1a<\/strong><\/p>\n<p>LIKE \u8fd0\u7b97\u7b26\u652f\u6301\u4ee5\u4e0b\u901a\u914d\u7b26\uff1a<\/p>\n<ul>\n<li> <strong>%<\/strong>\uff1a\u5339\u914d\u4efb\u610f\u6570\u91cf\u7684\u5b57\u7b26\u3002<\/li>\n<li> <strong>_<\/strong>\uff1a\u5339\u914d\u4efb\u4f55\u5355\u4e2a\u5b57\u7b26\u3002<\/li>\n<li> <strong>[]<\/strong>\uff1a\u5339\u914d\u65b9\u62ec\u53f7\u5185\u7684\u4efb\u4f55\u5b57\u7b26\uff08\u4f8b\u5982\uff0c [abc] \u5339\u914d a\u3001b \u6216 c\uff09\u3002<\/li>\n<li> <strong>[^]<\/strong>\uff1a\u5339\u914d\u4e0d\u5728\u65b9\u62ec\u53f7\u5185\u7684\u4efb\u4f55\u5b57\u7b26\uff08\u4f8b\u5982\uff0c <sup><\/sup> \u5339\u914d\u4efb\u4f55\u4e0d\u662f a\u3001b \u6216 c \u7684\u5b57\u7b26\uff09\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<ul>\n<li>\n<p>\u67e5\u627e\u4ee5 &#8220;John&#8221; \u5f00\u5934\u7684\u6240\u6709\u59d3\u540d\uff1a<\/p>\n<pre>SELECT name\nFROM employees\nWHERE name LIKE 'John%';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p>\u67e5\u627e\u5305\u542b &#8220;Doe&#8221; \u7684\u6240\u6709\u59d3\u6c0f\uff1a<\/p>\n<pre>SELECT last_name\nFROM employees\nWHERE last_name LIKE '%Doe';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p>\u67e5\u627e\u4e0d\u4ee5 &#8220;a&#8221; \u5f00\u5934\u7684\u6240\u6709\u57ce\u5e02\uff1a<\/p>\n<pre>SELECT city\nFROM addresses\nWHERE city NOT LIKE 'a%';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p>\u67e5\u627e\u5305\u542b\u6570\u5b57\u7684\u6240\u6709\u4ea7\u54c1\u540d\u79f0\uff1a<\/p>\n<pre>SELECT product_name\nFROM products\nWHERE product_name LIKE '%[0-9]%';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ul>\n<p><strong>\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>LIKE \u8fd0\u7b97\u7b26\u4e0d\u533a\u5206\u5927\u5c0f\u5199\u3002<\/li>\n<li>\u901a\u914d\u7b26\u53ea\u5339\u914d\u5217\u4e2d\u7684\u503c\uff0c\u4e0d\u5339\u914d\u5217\u540d\u6216\u8868\u540d\u3002<\/li>\n<li>\u4f7f\u7528\u901a\u914d\u7b26\u53ef\u80fd\u4f1a\u5bfc\u81f4\u67e5\u8be2\u6027\u80fd\u4e0b\u964d\uff0c\u7279\u522b\u662f\u5f53\u8868\u4e2d\u5305\u542b\u5927\u91cf\u6570\u636e\u65f6\u3002<\/li>\n<\/ul>\n<hr>\n<ol>\n<li>abc  <\/li>\n<\/ol>\n<p>\u4ee5\u4e0a\u5c31\u662fsql\u4e2dlike\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>sql \u4e2d like \u7528\u6cd5 LIKE \u8fd0\u7b97\u7b26\u7528\u4e8e\u5728 SQL \u67e5\u8be2\u4e2d\u5339\u914d\u5b57\u7b26\u4e32\u6a21\u5f0f\u3002\u5b83\u5141\u8bb8\u60a8\u67e5\u627e\u4e0e\u7279\u5b9a\u6a21\u5f0f\u76f8\u5339\u914d\u6216\u4ee5\u7279\u5b9a\u6a21\u5f0f\u5f00\u5934\u7684\u503c\u3002 \u8bed\u6cd5\uff1a SELECT column_name FROM table_name WHERE column_name LIKE &#8216;pattern&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a column_name \u662f\u60a8\u8981\u641c\u7d22\u7684\u5217\u3002 pattern \u662f\u60a8\u8981\u5339\u914d\u7684\u6a21\u5f0f\u3002 \u901a\u914d\u7b26\uff1a LIKE \u8fd0\u7b97\u7b26\u652f\u6301\u4ee5\u4e0b\u901a\u914d\u7b26\uff1a %\uff1a\u5339\u914d\u4efb\u610f\u6570\u91cf\u7684\u5b57\u7b26\u3002 _\uff1a\u5339\u914d\u4efb\u4f55\u5355\u4e2a\u5b57\u7b26\u3002 []\uff1a\u5339\u914d\u65b9\u62ec\u53f7\u5185\u7684\u4efb\u4f55\u5b57\u7b26\uff08\u4f8b\u5982\uff0c [abc] \u5339\u914d a\u3001b \u6216 c\uff09\u3002 [^]\uff1a\u5339\u914d\u4e0d\u5728\u65b9\u62ec\u53f7\u5185\u7684\u4efb\u4f55\u5b57\u7b26\uff08\u4f8b\u5982\uff0c \u5339\u914d\u4efb\u4f55\u4e0d\u662f a\u3001b \u6216 c \u7684\u5b57\u7b26\uff09\u3002 \u793a\u4f8b\uff1a \u67e5\u627e\u4ee5 &#8220;John&#8221; \u5f00\u5934\u7684\u6240\u6709\u59d3\u540d\uff1a SELECT name FROM employees WHERE name LIKE &#8216;John%&#8217;; \u767b\u5f55\u540e\u590d\u5236 \u67e5\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-5192","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5192","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=5192"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5192\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5192"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5192"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5192"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}