{"id":6905,"date":"2024-11-14T09:52:56","date_gmt":"2024-11-14T01:52:56","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6905\/"},"modified":"2024-11-14T09:52:56","modified_gmt":"2024-11-14T01:52:56","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-mysql-distinct-%e5%8e%bb%e9%87%8d%e5%b9%b6%e5%8c%ba%e5%88%86%e5%a2%83%e5%86%85%e5%a4%96%e5%9f%9f%e5%90%8d%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6905\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 MySQL DISTINCT \u53bb\u91cd\u5e76\u533a\u5206\u5883\u5185\u5916\u57df\u540d\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173007432324527.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 MySQL DISTINCT \u53bb\u91cd\u5e76\u533a\u5206\u5883\u5185\u5916\u57df\u540d\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 MySQL DISTINCT \u53bb\u91cd\u5e76\u533a\u5206\u5883\u5185\u5916\u57df\u540d\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong> \u6309\u6761\u4ef6\u8fdb\u884c distinct \u53bb\u91cd<\/strong><\/p>\n<p>\u4e3a\u4e86\u89e3\u51b3\u6309\u5b57\u6bb5 loc \u5bf9 domn \u8fdb\u884c\u53bb\u91cd\u7684\u95ee\u9898\uff0c\u9700\u8981\u8003\u8651\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<p><strong>\u4f7f\u7528 union all<\/strong><\/p>\n<pre>select distinct domain from url where loc = \"\u5883\u5916\" union all\n(select distinct domain from url where loc != \"\u5883\u5916\")<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u65b9\u6cd5\u5c06\u67e5\u8be2\u51fa\u6240\u6709\u5883\u5916\u57df\u540d\u548c\u975e\u5883\u5916\u57df\u540d\uff0c\u5e76\u5c06\u5b83\u4eec\u5408\u5e76\u4e3a\u4e00\u4e2a\u7ed3\u679c\u96c6\u3002<\/p>\n<p><strong>\u6309\u662f\u5426\u5883\u5916\u4eba\u4e3a\u589e\u52a0\u5b57\u6bb5<\/strong><\/p>\n<p>\u5982\u679c\u65e0\u6cd5\u5c06\u5883\u5185\u5916\u4fe1\u606f\u653e\u5165\u5355\u72ec\u7684\u5b57\u6bb5\u4e2d\uff0c\u5219\u53ef\u4ee5\u8003\u8651\u4eba\u4e3a\u589e\u52a0\u4e00\u4e2a\u5b57\u6bb5 is_out \u6765\u8868\u793a\u662f\u5426\u5883\u5916\uff1a<\/p>\n<pre>select distinct domain, is_out from url<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5982\u679c\u786e\u5b9a\u53ea\u6709 loc=&#8221;\u5883\u5916&#8221; \u4e3a\u5883\u5916\uff0c\u5219\u53ef\u4ee5\u6309\u7167\u5982\u4e0b\u7f16\u5199\u67e5\u8be2\u8bed\u53e5\uff1a<\/p>\n<pre>SELECT DISTINCT domain FROM url WHERE loc = \"\u5883\u5916\"<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 MySQL DISTINCT \u53bb\u91cd\u5e76\u533a\u5206\u5883\u5185\u5916\u57df\u540d\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>\u6309\u6761\u4ef6\u8fdb\u884c distinct \u53bb\u91cd \u4e3a\u4e86\u89e3\u51b3\u6309\u5b57\u6bb5 loc \u5bf9 domn \u8fdb\u884c\u53bb\u91cd\u7684\u95ee\u9898\uff0c\u9700\u8981\u8003\u8651\u4ee5\u4e0b\u65b9\u6cd5\uff1a \u4f7f\u7528 union all select distinct domain from url where loc = &#8220;\u5883\u5916&#8221; union all (select distinct domain from url where loc != &#8220;\u5883\u5916&#8221;) \u767b\u5f55\u540e\u590d\u5236 \u6b64\u65b9\u6cd5\u5c06\u67e5\u8be2\u51fa\u6240\u6709\u5883\u5916\u57df\u540d\u548c\u975e\u5883\u5916\u57df\u540d\uff0c\u5e76\u5c06\u5b83\u4eec\u5408\u5e76\u4e3a\u4e00\u4e2a\u7ed3\u679c\u96c6\u3002 \u6309\u662f\u5426\u5883\u5916\u4eba\u4e3a\u589e\u52a0\u5b57\u6bb5 \u5982\u679c\u65e0\u6cd5\u5c06\u5883\u5185\u5916\u4fe1\u606f\u653e\u5165\u5355\u72ec\u7684\u5b57\u6bb5\u4e2d\uff0c\u5219\u53ef\u4ee5\u8003\u8651\u4eba\u4e3a\u589e\u52a0\u4e00\u4e2a\u5b57\u6bb5 is_out \u6765\u8868\u793a\u662f\u5426\u5883\u5916\uff1a select distinct domain, is_out from url \u767b\u5f55\u540e\u590d\u5236 \u5982\u679c\u786e\u5b9a\u53ea\u6709 loc=&#8221;\u5883\u5916&#8221; \u4e3a\u5883\u5916\uff0c\u5219\u53ef\u4ee5\u6309\u7167\u5982\u4e0b\u7f16\u5199\u67e5\u8be2\u8bed\u53e5\uff1a SELECT DISTINCT domain FROM url WHERE loc = [&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-6905","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6905","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=6905"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6905\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6905"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6905"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6905"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}