{"id":6956,"date":"2024-11-14T13:28:12","date_gmt":"2024-11-14T05:28:12","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6956\/"},"modified":"2024-11-14T13:28:12","modified_gmt":"2024-11-14T05:28:12","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-sql-%e8%af%ad%e5%8f%a5%e5%88%a0%e9%99%a4%e5%8c%85%e5%90%ab%e7%89%b9%e5%ae%9a%e5%ad%97%e7%ac%a6%e7%9a%84%e8%b7%a8%e8%a1%a8%e6%95%b0%e6%8d%ae%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6956\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 SQL \u8bed\u53e5\u5220\u9664\u5305\u542b\u7279\u5b9a\u5b57\u7b26\u7684\u8de8\u8868\u6570\u636e\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173017778977415.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 SQL \u8bed\u53e5\u5220\u9664\u5305\u542b\u7279\u5b9a\u5b57\u7b26\u7684\u8de8\u8868\u6570\u636e\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 SQL \u8bed\u53e5\u5220\u9664\u5305\u542b\u7279\u5b9a\u5b57\u7b26\u7684\u8de8\u8868\u6570\u636e\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u7528\u5220\u9664\u591a\u8868\u4e2d\u7684\u5305\u542b\u7279\u5b9a\u5b57\u7b26\u7684\u6570\u636e<\/strong><\/p>\n<p>\u5df2\u77e5\u6709\u4e24\u5f20\u8868t1\u548ct2\uff0c\u8868t1\u7684\u5b57\u6bb5\u4e3aid\u548cusername\uff0c\u8868t2\u7684\u5b57\u6bb5\u4e3aid\u548cusername\uff0c\u7f16\u7801\u4e3agbk\u3002\u8868t1\u4e2d\u5305\u542b\u4ee5\u4e0b\u6570\u636e\uff1a<\/p>\n<pre>\u6570\u636e1: 1 c\u01d2c\u01d2\n\u6570\u636e2: 2 coco<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8868t2\u4e2d\u5305\u542b\u4ee5\u4e0b\u6570\u636e\uff1a<\/p>\n<pre>\u6570\u636e1: 1 c\u00f3c\u01d2<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u60a8\u9700\u8981\u4f7f\u7528utf8mb4\u6821\u5bf9\u96c6\u5220\u9664\u8fd9\u4e24\u4e2a\u8868\u4e2d\u6240\u6709\u5305\u542b&#8221;coco&#8221;\u5b57\u7b26\u7684\u6570\u636e\u3002\u9488\u5bf9\u5355\u8868\u7684\u5220\u9664\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\uff1a<\/p>\n<pre>delete from t1 where convert(username using utf8mb4) = convert(username using utf8mb4);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5bf9\u4e8e\u591a\u8868\u7684\u5220\u9664\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a<\/p>\n<pre>delete [low_priority] [quick] [ignore]\nfrom table_references\n[where where_condition]<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff0ctable_references\u6307\u5b9a\u8981\u5220\u9664\u6570\u636e\u7684\u8868\uff0cwhere_condition\u6307\u5b9a\u5220\u9664\u7684\u6761\u4ef6\u3002\u5728\u672c\u4f8b\u4e2d\uff0cwhere\u6761\u4ef6\u4e3ausername\u5305\u542bcoco\u5b57\u7b26\uff0c\u4f7f\u7528utf8mb4\u6821\u5bf9\u96c6\u8fdb\u884c\u6bd4\u8f83\u3002\u56e0\u6b64\uff0c\u6700\u7ec8\u7684\u591a\u8868\u5220\u9664\u8bed\u53e5\u4e3a\uff1a<\/p>\n<pre>DELETE\nFROM t1, t2\nWHERE convert(username USING utf8mb4) LIKE '%coco%'<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6267\u884c\u6b64\u8bed\u53e5\u540e\uff0ct1\u548ct2\u8868\u4e2d\u5305\u542bcoco\u5b57\u7b26\u7684\u6240\u6709\u6570\u636e\u5c06\u88ab\u5220\u9664\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 SQL \u8bed\u53e5\u5220\u9664\u5305\u542b\u7279\u5b9a\u5b57\u7b26\u7684\u8de8\u8868\u6570\u636e\uff1f\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>\u7528\u5220\u9664\u591a\u8868\u4e2d\u7684\u5305\u542b\u7279\u5b9a\u5b57\u7b26\u7684\u6570\u636e \u5df2\u77e5\u6709\u4e24\u5f20\u8868t1\u548ct2\uff0c\u8868t1\u7684\u5b57\u6bb5\u4e3aid\u548cusername\uff0c\u8868t2\u7684\u5b57\u6bb5\u4e3aid\u548cusername\uff0c\u7f16\u7801\u4e3agbk\u3002\u8868t1\u4e2d\u5305\u542b\u4ee5\u4e0b\u6570\u636e\uff1a \u6570\u636e1: 1 c\u01d2c\u01d2 \u6570\u636e2: 2 coco \u767b\u5f55\u540e\u590d\u5236 \u8868t2\u4e2d\u5305\u542b\u4ee5\u4e0b\u6570\u636e\uff1a \u6570\u636e1: 1 c\u00f3c\u01d2 \u767b\u5f55\u540e\u590d\u5236 \u60a8\u9700\u8981\u4f7f\u7528utf8mb4\u6821\u5bf9\u96c6\u5220\u9664\u8fd9\u4e24\u4e2a\u8868\u4e2d\u6240\u6709\u5305\u542b&#8221;coco&#8221;\u5b57\u7b26\u7684\u6570\u636e\u3002\u9488\u5bf9\u5355\u8868\u7684\u5220\u9664\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u53e5\uff1a delete from t1 where convert(username using utf8mb4) = convert(username using utf8mb4); \u767b\u5f55\u540e\u590d\u5236 \u5bf9\u4e8e\u591a\u8868\u7684\u5220\u9664\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u8bed\u6cd5\uff1a delete [low_priority] [quick] [ignore] from table_references [where where_condition] \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff0ctable_references\u6307\u5b9a\u8981\u5220\u9664\u6570\u636e\u7684\u8868\uff0cwhere_condition\u6307\u5b9a\u5220\u9664\u7684\u6761\u4ef6\u3002\u5728\u672c\u4f8b\u4e2d\uff0cwhere\u6761\u4ef6\u4e3ausername\u5305\u542bcoco\u5b57\u7b26\uff0c\u4f7f\u7528utf8mb4\u6821\u5bf9\u96c6\u8fdb\u884c\u6bd4\u8f83\u3002\u56e0\u6b64\uff0c\u6700\u7ec8\u7684\u591a\u8868\u5220\u9664\u8bed\u53e5\u4e3a\uff1a DELETE FROM t1, t2 WHERE convert(username USING utf8mb4) LIKE &#8216;%coco%&#8217; \u767b\u5f55\u540e\u590d\u5236 \u6267\u884c\u6b64\u8bed\u53e5\u540e\uff0ct1\u548ct2\u8868\u4e2d\u5305\u542bcoco\u5b57\u7b26\u7684\u6240\u6709\u6570\u636e\u5c06\u88ab\u5220\u9664\u3002 \u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 SQL \u8bed\u53e5\u5220\u9664\u5305\u542b\u7279\u5b9a\u5b57\u7b26\u7684\u8de8\u8868\u6570\u636e\uff1f\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},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-6956","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6956","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=6956"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6956\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6956"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6956"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6956"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}