{"id":6903,"date":"2024-11-14T11:40:20","date_gmt":"2024-11-14T03:40:20","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6903\/"},"modified":"2024-11-14T11:40:20","modified_gmt":"2024-11-14T03:40:20","slug":"%e5%a6%82%e4%bd%95%e4%bd%bf%e7%94%a8-distinct-%e5%85%b3%e9%94%ae%e5%ad%97%e5%9c%a8-mysql-%e4%b8%ad%e6%8c%89%e6%9d%a1%e4%bb%b6%e5%8e%bb%e9%87%8d%e5%ad%97%e6%ae%b5%ef%bc%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6903\/","title":{"rendered":"\u5982\u4f55\u4f7f\u7528 DISTINCT \u5173\u952e\u5b57\u5728 MySQL \u4e2d\u6309\u6761\u4ef6\u53bb\u91cd\u5b57\u6bb5\uff1f"},"content":{"rendered":"<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/001\/246\/273\/173007414455050.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u4f7f\u7528 DISTINCT \u5173\u952e\u5b57\u5728 MySQL \u4e2d\u6309\u6761\u4ef6\u53bb\u91cd\u5b57\u6bb5\uff1f\u63d2\u56fe\" alt=\"\u5982\u4f55\u4f7f\u7528 DISTINCT \u5173\u952e\u5b57\u5728 MySQL \u4e2d\u6309\u6761\u4ef6\u53bb\u91cd\u5b57\u6bb5\uff1f\u63d2\u56fe\" \/><\/p>\n<p><strong> \u4e2d\u6309\u6761\u4ef6 distinct \u5b57\u6bb5<\/strong><\/p>\n<p>\u5728 mysql \u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7 distinct \u5173\u952e\u5b57\u5bf9\u67e5\u8be2\u7ed3\u679c\u4e2d\u7684\u91cd\u590d\u503c\u8fdb\u884c\u7b5b\u9009\u3002\u4e0d\u8fc7\uff0c\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u9700\u8981\u6839\u636e\u7279\u5b9a\u6761\u4ef6\u5bf9\u5b57\u6bb5\u8fdb\u884c distinct \u64cd\u4f5c\u3002<\/p>\n<p>\u6839\u636e\u6240\u7ed9\u7684\u8868\u7ed3\u6784\uff0c\u7528\u6237\u5e0c\u671b\u6309 domn \u5b57\u6bb5\u8fdb\u884c\u53bb\u91cd\uff0c\u4f46\u9700\u8981\u533a\u5206 \u5883\u5185 \u548c \u5883\u5916\u3002\u5bf9\u4e8e\u6b64\u7c7b\u9700\u6c42\uff0c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a<\/p>\n<p>\u5982\u679c\u6570\u636e\u5e93\u4e2d\u5b58\u5728\u4e00\u4e2a\u5b57\u6bb5\u8868\u793a\u662f\u5426\u5883\u5916\uff0c\u4f8b\u5982 isout\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528 distinct \u5173\u952e\u5b57\u7ed3\u5408 isout \u5b57\u6bb5\u8fdb\u884c\u53bb\u91cd\uff1a<\/p>\n<pre>select distinct domain, isout from url;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5982\u679c\u6570\u636e\u5e93\u4e2d\u6ca1\u6709\u5b57\u6bb5\u8868\u793a\u662f\u5426\u5883\u5916\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8be2\u8bed\u53e5\u5bf9 loc \u5b57\u6bb5\u8fdb\u884c\u53bb\u91cd\uff0c\u5e76\u4e14\u533a\u5206 \u5883\u5185 \u548c \u5883\u5916\uff1a<\/p>\n<pre>SELECT DISTINCT domain\nFROM url\nWHERE loc = \"\u5883\u5916\"\nUNION ALL\n(\n  SELECT DISTINCT domain\n  FROM url\n  WHERE loc != \"\u5883\u5916\"\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u67e5\u8be2\u8bed\u53e5\u4f7f\u7528 union all \u64cd\u4f5c\u5c06 loc \u7b49\u4e8e \u5883\u5916 \u7684\u8bb0\u5f55\u4e0e loc \u4e0d\u7b49\u4e8e \u5883\u5916 \u7684\u8bb0\u5f55\u5408\u5e76\uff0c\u540c\u65f6\u786e\u4fdd domain \u5b57\u6bb5\u53bb\u91cd\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u4f7f\u7528 DISTINCT \u5173\u952e\u5b57\u5728 MySQL \u4e2d\u6309\u6761\u4ef6\u53bb\u91cd\u5b57\u6bb5\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>\u4e2d\u6309\u6761\u4ef6 distinct \u5b57\u6bb5 \u5728 mysql \u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7 distinct \u5173\u952e\u5b57\u5bf9\u67e5\u8be2\u7ed3\u679c\u4e2d\u7684\u91cd\u590d\u503c\u8fdb\u884c\u7b5b\u9009\u3002\u4e0d\u8fc7\uff0c\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u9700\u8981\u6839\u636e\u7279\u5b9a\u6761\u4ef6\u5bf9\u5b57\u6bb5\u8fdb\u884c distinct \u64cd\u4f5c\u3002 \u6839\u636e\u6240\u7ed9\u7684\u8868\u7ed3\u6784\uff0c\u7528\u6237\u5e0c\u671b\u6309 domn \u5b57\u6bb5\u8fdb\u884c\u53bb\u91cd\uff0c\u4f46\u9700\u8981\u533a\u5206 \u5883\u5185 \u548c \u5883\u5916\u3002\u5bf9\u4e8e\u6b64\u7c7b\u9700\u6c42\uff0c\u53ef\u4ee5\u91c7\u7528\u4ee5\u4e0b\u65b9\u6cd5\uff1a \u5982\u679c\u6570\u636e\u5e93\u4e2d\u5b58\u5728\u4e00\u4e2a\u5b57\u6bb5\u8868\u793a\u662f\u5426\u5883\u5916\uff0c\u4f8b\u5982 isout\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528 distinct \u5173\u952e\u5b57\u7ed3\u5408 isout \u5b57\u6bb5\u8fdb\u884c\u53bb\u91cd\uff1a select distinct domain, isout from url; \u767b\u5f55\u540e\u590d\u5236 \u5982\u679c\u6570\u636e\u5e93\u4e2d\u6ca1\u6709\u5b57\u6bb5\u8868\u793a\u662f\u5426\u5883\u5916\uff0c\u5219\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8be2\u8bed\u53e5\u5bf9 loc \u5b57\u6bb5\u8fdb\u884c\u53bb\u91cd\uff0c\u5e76\u4e14\u533a\u5206 \u5883\u5185 \u548c \u5883\u5916\uff1a SELECT DISTINCT domain FROM url WHERE loc = &#8220;\u5883\u5916&#8221; UNION ALL ( 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-6903","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6903","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=6903"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6903\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6903"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6903"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6903"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}