{"id":7136,"date":"2024-11-14T15:17:57","date_gmt":"2024-11-14T07:17:57","guid":{"rendered":"https:\/\/fwq.ai\/blog\/7136\/"},"modified":"2024-11-14T15:17:57","modified_gmt":"2024-11-14T07:17:57","slug":"mysql-8-0-%e4%b8%ad%ef%bc%8cunion-%e6%9f%a5%e8%af%a2%e7%bb%93%e6%9e%9c%e6%8e%92%e5%ba%8f%e4%b8%8e-union-%e9%a1%ba%e5%ba%8f%e4%b8%8d%e4%b8%80%e8%87%b4%ef%bc%8c%e5%a6%82%e4%bd%95%e8%a7%a3%e5%86%b3","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/7136\/","title":{"rendered":"MySQL 8.0 \u4e2d\uff0cunion \u67e5\u8be2\u7ed3\u679c\u6392\u5e8f\u4e0e union \u987a\u5e8f\u4e0d\u4e00\u81f4\uff0c\u5982\u4f55\u89e3\u51b3\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173047133443580.jpg\" class=\"aligncenter\" title=\"MySQL 8.0 \u4e2d\uff0cunion \u67e5\u8be2\u7ed3\u679c\u6392\u5e8f\u4e0e union \u987a\u5e8f\u4e0d\u4e00\u81f4\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" alt=\"MySQL 8.0 \u4e2d\uff0cunion \u67e5\u8be2\u7ed3\u679c\u6392\u5e8f\u4e0e union \u987a\u5e8f\u4e0d\u4e00\u81f4\uff0c\u5982\u4f55\u89e3\u51b3\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong> union \u67e5\u8be2\u6392\u5e8f\u4e0e union \u987a\u5e8f\u7684\u5173\u7cfb<\/strong><\/p>\n<p>\u60a8\u7684\u95ee\u9898\u662f mysql 8.0 \u4e2d\uff0cunion \u67e5\u8be2\u7684\u7ed3\u679c\u6392\u5e8f\u4e0e union \u672c\u8eab\u987a\u5e8f\u4e0d\u4e00\u81f4\u3002\u5728\u8f83\u65e9\u7684 mysql \u7248\u672c\u4e2d\uff0c\u8fd9\u79cd\u6392\u5e8f\u7ed3\u679c\u662f\u7b26\u5408\u9884\u671f\u7684\u3002<\/p>\n<p><strong>\u539f\u56e0<\/strong><\/p>\n<p>\u5728 mysql 8.0 \u4e2d\uff0cunion \u67e5\u8be2\u91c7\u7528\u4e86\u65b0\u7684\u6392\u5e8f\u7b97\u6cd5\uff0c\u8be5\u7b97\u6cd5\u4ee5\u6bcf\u4e2a\u67e5\u8be2\u7ed3\u679c\u96c6\u4e2d\u5339\u914d\u6761\u4ef6\u7684\u5217\u4e3a\u4f9d\u636e\u8fdb\u884c\u6392\u5e8f\u3002\u8fd9\u610f\u5473\u7740\uff0c\u5982\u679c\u67d0\u4e2a\u67e5\u8be2\u7ed3\u679c\u96c6\u4e2d\u5339\u914d\u4e86\u591a\u4e2a\u6761\u4ef6\uff0c\u5219\u5b83\u5728 union \u7ed3\u679c\u4e2d\u7684\u987a\u5e8f\u4f1a\u4f18\u5148\u4e8e\u5339\u914d\u8f83\u5c11\u6761\u4ef6\u7684\u67e5\u8be2\u3002<\/p>\n<p><strong>\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u4e3a\u4e86\u6309\u7167 union \u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6280\u5de7\uff1a<\/p>\n<p><strong>1. case when \u8bed\u53e5<\/strong><\/p>\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528 case when \u8bed\u53e5\u4e3a\u6bcf\u4e2a union \u67e5\u8be2\u7ed3\u679c\u5206\u914d\u4e00\u4e2a\u4f18\u5148\u7ea7\u5e8f\u53f7\uff1a<\/p>\n<pre>select  \n`id`\n,`class_id`\n,`active`\n,`add_time`\n,`show_time`\n,`url_prefix`\n,`subject`\nfrom `glfr_article`\nwhere\n`active` = '1' \nand `show_time` &lt; 1655278257\nand ( `subject` like '%mysql%' or `subject` like '%\u5bfc\u5165%' or `subject` like '%\u5bfc\u51fa%' )\norder by \ncase subject like '%mysql\u5bfc\u5165\u5bfc\u51fa%' when true then 0 else 1 end, \ncase subject like '%mysql%' when true then 0 else 1 end, \ncase subject like '%\u5bfc\u5165%' when true then 0 else 1 end, \ncase subject like '%\u5bfc\u51fa%' when true then 0 else 1 end\n;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u5339\u914d\u8bcd\u4e2a\u6570\u6392\u5e8f<\/strong><\/p>\n<p>\u5982\u679c\u60a8\u9700\u8981\u6839\u636e\u5339\u914d\u8bcd\u7684\u4e2a\u6570\u964d\u5e8f\u6392\u5e8f\uff0c\u53ef\u4ee5\u4f7f\u7528\u5982\u4e0b\u67e5\u8be2\uff1a<\/p>\n<pre>SELECT  \n`id`\n,`class_id`\n,`active`\n,`add_time`\n,`show_time`\n,`url_prefix`\n,`subject`\n,(length(replace(replace(replace(subject, 'MySQL', 'MySQL_'), '\u5bfc\u5165', '\u5bfc\u5165_'), '\u5bfc\u51fa', '\u5bfc\u51fa_')) - length(subject)) as 'point'\nFROM `glfr_article`\nWHERE\n`active` = '1' \nAND `show_time` &lt; 1655278257\nAND ( `subject` LIKE '%MySQL%' OR `subject` LIKE '%\u5bfc\u5165%' OR `subject` LIKE '%\u5bfc\u51fa%' )\nORDER BY \nlength(replace(replace(replace(subject, 'MySQL', 'MySQL_'), '\u5bfc\u5165', '\u5bfc\u5165_'), '\u5bfc\u51fa', '\u5bfc\u51fa_')) - length(subject) desc<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662fMySQL 8.0 \u4e2d\uff0cunion \u67e5\u8be2\u7ed3\u679c\u6392\u5e8f\u4e0e union \u987a\u5e8f\u4e0d\u4e00\u81f4\uff0c\u5982\u4f55\u89e3\u51b3\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>union \u67e5\u8be2\u6392\u5e8f\u4e0e union \u987a\u5e8f\u7684\u5173\u7cfb \u60a8\u7684\u95ee\u9898\u662f mysql 8.0 \u4e2d\uff0cunion \u67e5\u8be2\u7684\u7ed3\u679c\u6392\u5e8f\u4e0e union \u672c\u8eab\u987a\u5e8f\u4e0d\u4e00\u81f4\u3002\u5728\u8f83\u65e9\u7684 mysql \u7248\u672c\u4e2d\uff0c\u8fd9\u79cd\u6392\u5e8f\u7ed3\u679c\u662f\u7b26\u5408\u9884\u671f\u7684\u3002 \u539f\u56e0 \u5728 mysql 8.0 \u4e2d\uff0cunion \u67e5\u8be2\u91c7\u7528\u4e86\u65b0\u7684\u6392\u5e8f\u7b97\u6cd5\uff0c\u8be5\u7b97\u6cd5\u4ee5\u6bcf\u4e2a\u67e5\u8be2\u7ed3\u679c\u96c6\u4e2d\u5339\u914d\u6761\u4ef6\u7684\u5217\u4e3a\u4f9d\u636e\u8fdb\u884c\u6392\u5e8f\u3002\u8fd9\u610f\u5473\u7740\uff0c\u5982\u679c\u67d0\u4e2a\u67e5\u8be2\u7ed3\u679c\u96c6\u4e2d\u5339\u914d\u4e86\u591a\u4e2a\u6761\u4ef6\uff0c\u5219\u5b83\u5728 union \u7ed3\u679c\u4e2d\u7684\u987a\u5e8f\u4f1a\u4f18\u5148\u4e8e\u5339\u914d\u8f83\u5c11\u6761\u4ef6\u7684\u67e5\u8be2\u3002 \u89e3\u51b3\u65b9\u6848 \u4e3a\u4e86\u6309\u7167 union \u987a\u5e8f\u8fd4\u56de\u7ed3\u679c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u6280\u5de7\uff1a 1. case when \u8bed\u53e5 \u60a8\u53ef\u4ee5\u4f7f\u7528 case when \u8bed\u53e5\u4e3a\u6bcf\u4e2a union \u67e5\u8be2\u7ed3\u679c\u5206\u914d\u4e00\u4e2a\u4f18\u5148\u7ea7\u5e8f\u53f7\uff1a select `id` ,`class_id` ,`active` ,`add_time` ,`show_time` ,`url_prefix` ,`subject` from `glfr_article` where `active` = &#8216;1&#8217; and `show_time` &lt; 1655278257 and ( [&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-7136","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7136","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=7136"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/7136\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=7136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=7136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=7136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}