{"id":203110,"date":"2025-05-22T12:59:15","date_gmt":"2025-05-22T04:59:15","guid":{"rendered":"https:\/\/server.hk\/cnblog\/203110\/"},"modified":"2025-05-22T12:59:15","modified_gmt":"2025-05-22T04:59:15","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8-mysql-%e4%b8%ad%e9%ab%98%e6%95%88%e4%bc%98%e5%8c%96%e4%b8%80%e5%8d%83%e4%b8%87%e6%95%b0%e6%8d%ae%e9%87%8f%e7%9a%84%e6%a8%a1%e7%b3%8a%e6%90%9c%e7%b4%a2%ef%bc%8c%e5%ae%9e","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/203110\/","title":{"rendered":"## \u5982\u4f55\u5728 MySQL \u4e2d\u9ad8\u6548\u4f18\u5316\u4e00\u5343\u4e07\u6570\u636e\u91cf\u7684\u6a21\u7cca\u641c\u7d22\uff0c\u5b9e\u73b0\u4e00\u79d2\u5185\u54cd\u5e94\uff1f"},"content":{"rendered":"<p><b><\/b>     <\/p>\n<h1>## \u5982\u4f55\u5728 MySQL \u4e2d\u9ad8\u6548\u4f18\u5316\u4e00\u5343\u4e07\u6570\u636e\u91cf\u7684\u6a21\u7cca\u641c\u7d22\uff0c\u5b9e\u73b0\u4e00\u79d2\u5185\u54cd\u5e94\uff1f<\/h1>\n<p>\u73cd\u60dc\u65f6\u95f4\uff0c\u52e4\u594b\u5b66\u4e60\uff01\u4eca\u5929\u7ed9\u5927\u5bb6\u5e26\u6765<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a## \u5982\u4f55\u5728 MySQL \u4e2d\u9ad8\u6548\u4f18\u5316\u4e00\u5343\u4e07\u6570\u636e\u91cf\u7684\u6a21\u7cca\u641c\u7d22\uff0c\u5b9e\u73b0\u4e00\u79d2\u5185\u54cd\u5e94\uff1f\u300b<\/span>\uff0c\u6b63\u6587\u5185\u5bb9\u4e3b\u8981\u6d89\u53ca\u5230<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\uff0c\u5982\u679c\u4f60\u6b63\u5728\u5b66\u4e60<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\uff0c\u6216\u8005\u662f\u5bf9<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u6587\u7ae0<\/span>\u6709\u7591\u95ee\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u6211\uff01\u540e\u9762\u6211\u4f1a\u6301\u7eed\u66f4\u65b0\u76f8\u5173\u5185\u5bb9\u7684\uff0c\u5e0c\u671b\u90fd\u80fd\u5e2e\u5230\u6b63\u5728\u5b66\u4e60\u7684\u5927\u5bb6\uff01<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.17golang.com\/uploads\/20241028\/1730097953671f33216695c.jpg\" class=\"aligncenter\"><\/p>\n<p><strong>\u5982\u4f55\u4f18\u5316mysql \u4e2d\u4e00\u5343\u4e07\u6570\u636e\u91cf\u7684\u6a21\u7cca\u641c\u7d22\uff0c\u5b9e\u73b0\u4e00\u79d2\u5185\u54cd\u5e94<\/strong><\/p>\n<p>\u5728mysql \u4e2d\uff0c\u4e3a\u4e00\u5343\u4e07\u7684\u6570\u636e\u91cf\u5b9e\u73b0\u9ad8\u6548\u7684\u6a21\u7cca\u67e5\u8be2\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u96be\u9898\u3002\u672c\u6587\u5c06\u63a2\u8ba8\u4e00\u79cd\u901a\u8fc7\u521b\u5efa\u7d22\u5f15\u8868\u6765\u89e3\u51b3\u8fd9\u4e00\u95ee\u9898\u7684\u65b9\u6848\u3002 <\/p>\n<p><strong>\u95ee\u9898\u80cc\u666f\uff1a<\/strong><\/p>\n<ul>\n<li>\u6570\u636e\u5e93\uff1amysql 5.7<\/li>\n<li>\u6570\u636e\u91cf\uff1a\u4e00\u5343\u4e07\u6761<\/li>\n<li>\u6a21\u7cca\u67e5\u8be2\uff1a select * from table where title like %\u5173\u952e\u8bcd% limit 100<\/li>\n<li>\u9650\u5b9a\u6761\u4ef6\uff1a\u9650\u5236\u8fd4\u56de\u524d100 \u6761\u6570\u636e<\/li>\n<\/ul>\n<p><strong>\u4f20\u7edf\u65b9\u6cd5\u7684\u5c40\u9650\u6027\uff1a<\/strong><\/p>\n<p>\u4f20\u7edf\u7684\u6a21\u7cca\u641c\u7d22\u8d70\u4e0d\u4e86\u7d22\u5f15\uff0c\u5bfc\u81f4\u6bcf\u6b21\u67e5\u8be2\u90fd\u9700\u8981\u5168\u8868\u626b\u63cf\uff0c\u901f\u5ea6\u6781\u6162\u3002 <\/p>\n<p><strong>\u7d22\u5f15\u8868\u65b9\u6848\uff1a<\/strong><\/p>\n<p>\u6211\u4eec\u53ef\u4ee5\u521b\u5efa\u4e00\u4e2a\u7d22\u5f15\u8868\uff0c\u5176\u4e2d\u5305\u542b\u5f53\u524d\u8bcd\u3001\u4e0b\u4e00\u8bcd\u548c\u539f\u8bb0\u5f55\u7684\u4e3b\u952e id\u3002\u5bf9\u4e8e\u7ed9\u5b9a\u7684\u641c\u7d22\u8bcd\uff0c\u6211\u4eec\u53ef\u4ee5\u6839\u636e\u5f53\u524d\u8bcd\u548c\u4e0b\u4e00\u8bcd\u5728\u7d22\u5f15\u8868\u4e2d\u67e5\u627e\u5339\u914d\u7684\u8bb0\u5f55\uff0c\u7136\u540e\u901a\u8fc7\u4e3b\u952e id \u5173\u8054\u56de\u539f\u8bb0\u5f55\uff0c\u4ece\u800c\u5b9e\u73b0\u9ad8\u6548\u7684\u6a21\u7cca\u641c\u7d22\u3002 <\/p>\n<p><strong>\u7d22\u5f15\u8868\u7ed3\u6784\uff1a<\/strong><\/p>\n<table>\n<thead>\n<tr>\n<th>\u5f53\u524d\u8bcd<\/th>\n<th>\u4e0b\u4e00\u8bcd<\/th>\n<th>\u539f\u8bb0\u5f55\u4e3b\u952e id<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>mysql<\/td>\n<td>\u4e00<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>\u4e00<\/td>\n<td>\u5343<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>\u5343<\/td>\n<td>\u4e07<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>\u4e07<\/td>\n<td>\u7684<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>&#8230;<\/td>\n<td>&#8230;<\/td>\n<td>&#8230;<\/td>\n<\/tr>\n<tr>\n<td>\u6a21<\/td>\n<td>\u7cca<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>\u7cca<\/td>\n<td>\u641c<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>\u641c<\/td>\n<td>\u7d22<\/td>\n<td>1<\/td>\n<\/tr>\n<tr>\n<td>\u7d22<\/td>\n<td>null<\/td>\n<td>1<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u67e5\u8be2\u793a\u4f8b\uff1a<\/strong><\/p>\n<p>\u4ee5\u641c\u7d22\u201c\u6a21\u7cca\u641c\u7d22\u201d\u4e3a\u4f8b\uff0c\u67e5\u8be2\u8bed\u53e5\u5982\u4e0b\uff1a<\/p>\n<pre>SELECT \u539f\u8bb0\u5f55\u4e3b\u952eID\nFROM (SELECT \u539f\u8bb0\u5f55\u4e3b\u952eID FROM \u7d22\u5f15\u8868 WHERE \u5f53\u524d\u8bcd = '\u6a21' AND \u4e0b\u4e00\u8bcd = '\u7cca')\nJOIN (SELECT \u539f\u8bb0\u5f55\u4e3b\u952eID FROM \u7d22\u5f15\u8868 WHERE \u5f53\u524d\u8bcd = '\u7cca' AND \u4e0b\u4e00\u8bcd = '\u641c') USING(\u539f\u8bb0\u5f55\u4e3b\u952eID)\nJOIN (SELECT \u539f\u8bb0\u5f55\u4e3b\u952eID FROM \u7d22\u5f15\u8868 WHERE \u5f53\u524d\u8bcd = '\u641c' AND \u4e0b\u4e00\u8bcd = '\u7d22') USING(\u539f\u8bb0\u5f55\u4e3b\u952eID)\nJOIN (SELECT \u539f\u8bb0\u5f55\u4e3b\u952eID FROM \u7d22\u5f15\u8868 WHERE \u5f53\u524d\u8bcd = '\u7d22' AND \u4e0b\u4e00\u8bcd IS NULL) USING(\u539f\u8bb0\u5f55\u4e3b\u952eID)<\/pre>\n<p>\u901a\u8fc7\u5c06\u67e5\u8be2\u62c6\u5206\u6210\u591a\u4e2a\u7b80\u5355\u7684\u5173\u8054\u67e5\u8be2\uff0c\u6211\u4eec\u53ef\u4ee5\u5feb\u901f\u627e\u5230\u5339\u914d\u7684\u539f\u8bb0\u5f55\u4e3b\u952eid\uff0c\u4ece\u800c\u5927\u5927\u63d0\u5347\u6a21\u7cca\u67e5\u8be2\u7684\u6548\u7387\u3002 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u300a## \u5982\u4f55\u5728 MySQL \u4e2d\u9ad8\u6548\u4f18\u5316\u4e00\u5343\u4e07\u6570\u636e\u91cf\u7684\u6a21\u7cca\u641c\u7d22\uff0c\u5b9e\u73b0\u4e00\u79d2\u5185\u54cd\u5e94\uff1f\u300b\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u5173\u4e8e\u7684\u8d44\u6599\u8bf7\u5173\u6ce8\u516c\u4f17\u53f7\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>## \u5982\u4f55\u5728 MySQL \u4e2d\u9ad8\u6548&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-203110","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203110","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"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=203110"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/203110\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=203110"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=203110"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=203110"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}