{"id":6100,"date":"2024-11-14T08:12:42","date_gmt":"2024-11-14T00:12:42","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6100\/"},"modified":"2024-11-14T08:12:42","modified_gmt":"2024-11-14T00:12:42","slug":"oracle%e5%a6%82%e4%bd%95%e5%8e%bb%e9%87%8d%e6%9f%a5%e8%af%a2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6100\/","title":{"rendered":"oracle\u5982\u4f55\u53bb\u91cd\u67e5\u8be2"},"content":{"rendered":"<blockquote><p>\n  oracle \u63d0\u4f9b\u591a\u79cd\u53bb\u91cd\u67e5\u8be2\u65b9\u6cd5\uff1adistinct \u5173\u952e\u5b57\u8fd4\u56de\u6bcf\u5217\u7684\u552f\u4e00\u503c\u3002group by \u5b50\u53e5\u5bf9\u7ed3\u679c\u5206\u7ec4\u5e76\u8fd4\u56de\u6bcf\u4e2a\u5206\u7ec4\u7684\u975e\u91cd\u590d\u503c\u3002unique \u5173\u952e\u5b57\u7528\u4e8e\u521b\u5efa\u4ec5\u5305\u542b\u552f\u4e00\u884c\u7684\u7d22\u5f15\uff0c\u67e5\u8be2\u8be5\u7d22\u5f15\u5c06\u81ea\u52a8\u53bb\u91cd\u3002row_number() \u51fd\u6570\u5206\u914d\u552f\u4e00\u6570\u5b57\u5e76\u8fc7\u6ee4\u51fa\u4ec5\u5305\u542b\u7b2c 1 \u884c\u7684\u7ed3\u679c\u3002min() \u6216 max() \u51fd\u6570\u53ef\u8fd4\u56de\u6570\u5b57\u5217\u7684\u975e\u91cd\u590d\u503c\u3002intersect \u8fd0\u7b97\u7b26\u8fd4\u56de\u4e24\u4e2a\u7ed3\u679c\u96c6\u7684\u516c\u5171\u503c\uff08\u65e0\u91cd\u590d\u9879\uff09\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/12\/2024061223122187733.jpg\" class=\"aligncenter\" title=\"oracle\u5982\u4f55\u53bb\u91cd\u67e5\u8be2\u63d2\u56fe\" alt=\"oracle\u5982\u4f55\u53bb\u91cd\u67e5\u8be2\u63d2\u56fe\" \/><\/p>\n<p><strong>Oracle \u53bb\u91cd\u67e5\u8be2<\/strong><\/p>\n<p>Oracle \u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u6cd5\u6765\u6267\u884c\u53bb\u91cd\u67e5\u8be2\uff0c\u5373\u4ece\u7ed3\u679c\u96c6\u4e2d\u5220\u9664\u91cd\u590d\u503c\u3002<\/p>\n<p><strong>1. DISTINCT \u5173\u952e\u5b57<\/strong><\/p>\n<p>DISTINCT \u5173\u952e\u5b57\u662f\u6700\u7b80\u5355\u7684\u53bb\u91cd\u65b9\u6cd5\u3002\u5b83\u7528\u4e8e\u8fd4\u56de\u7ed3\u679c\u96c6\u4e2d\u6bcf\u5217\u7684\u552f\u4e00\u503c\u3002<\/p>\n<pre>SELECT DISTINCT column_name\nFROM table_name;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. GROUP BY \u5b50\u53e5<\/strong><\/p>\n<p>GROUP BY \u5b50\u53e5\u5c06\u7ed3\u679c\u96c6\u5206\u7ec4\uff0c\u5e76\u4ec5\u8fd4\u56de\u6bcf\u4e2a\u5206\u7ec4\u7684\u975e\u91cd\u590d\u503c\u3002<\/p>\n<pre>SELECT column_name\nFROM table_name\nGROUP BY column_name;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. UNIQUE \u5173\u952e\u5b57<\/strong><\/p>\n<p>UNIQUE \u5173\u952e\u5b57\u53ef\u7528\u4e8e\u521b\u5efa\u7d22\u5f15\uff0c\u8be5\u7d22\u5f15\u4ec5\u5305\u542b\u8868\u7684\u552f\u4e00\u884c\u3002\u67e5\u8be2\u6b64\u7c7b\u7d22\u5f15\u5c06\u81ea\u52a8\u53bb\u91cd\u3002<\/p>\n<pre>CREATE UNIQUE INDEX index_name ON table_name (column_name);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. ROW_NUMBER() \u51fd\u6570<\/strong><\/p>\n<p>ROW_NUMBER() \u51fd\u6570\u4e3a\u7ed3\u679c\u96c6\u4e2d\u7684\u6bcf\u4e00\u884c\u5206\u914d\u4e00\u4e2a\u552f\u4e00\u7684\u6570\u5b57\u3002\u7136\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u8fc7\u6ee4\u51fa\u4ec5\u5305\u542b\u7b2c 1 \u884c\u7684\u53bb\u91cd\u590d\u7ed3\u679c\u3002<\/p>\n<pre>SELECT column_name\nFROM (\n    SELECT column_name, ROW_NUMBER() OVER (ORDER BY column_name) AS row_num\n    FROM table_name\n) AS subquery\nWHERE row_num = 1;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. MIN() \u6216 MAX() \u51fd\u6570<\/strong><\/p>\n<p>\u5bf9\u4e8e\u6570\u5b57\u5217\uff0c\u53ef\u4ee5\u4f7f\u7528 MIN() \u6216 MAX() \u51fd\u6570\u6765\u8fd4\u56de\u975e\u91cd\u590d\u503c\u3002<\/p>\n<pre>SELECT MIN(column_name)\nFROM table_name;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<pre>SELECT MAX(column_name)\nFROM table_name;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>6. INTERSECT \u8fd0\u7b97\u7b26<\/strong><\/p>\n<p>INTERSECT \u8fd0\u7b97\u7b26\u5c06\u4e24\u4e2a\u7ed3\u679c\u96c6\u76f8\u4ea4\uff0c\u4ec5\u8fd4\u56de\u5b83\u4eec\u7684\u516c\u5171\u503c\uff08\u5373\u6ca1\u6709\u91cd\u590d\u503c\uff09\u3002<\/p>\n<pre>SELECT column_name\nFROM table_name\nINTERSECT\nSELECT column_name\nFROM table_name2;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u53bb\u91cd\u67e5\u8be2\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>oracle \u63d0\u4f9b\u591a\u79cd\u53bb\u91cd\u67e5\u8be2\u65b9\u6cd5\uff1adistinct \u5173\u952e\u5b57\u8fd4\u56de\u6bcf\u5217\u7684\u552f\u4e00\u503c\u3002group by \u5b50\u53e5\u5bf9\u7ed3\u679c\u5206\u7ec4\u5e76\u8fd4\u56de\u6bcf\u4e2a\u5206\u7ec4\u7684\u975e\u91cd\u590d\u503c\u3002unique \u5173\u952e\u5b57\u7528\u4e8e\u521b\u5efa\u4ec5\u5305\u542b\u552f\u4e00\u884c\u7684\u7d22\u5f15\uff0c\u67e5\u8be2\u8be5\u7d22\u5f15\u5c06\u81ea\u52a8\u53bb\u91cd\u3002row_number() \u51fd\u6570\u5206\u914d\u552f\u4e00\u6570\u5b57\u5e76\u8fc7\u6ee4\u51fa\u4ec5\u5305\u542b\u7b2c 1 \u884c\u7684\u7ed3\u679c\u3002min() \u6216 max() \u51fd\u6570\u53ef\u8fd4\u56de\u6570\u5b57\u5217\u7684\u975e\u91cd\u590d\u503c\u3002intersect \u8fd0\u7b97\u7b26\u8fd4\u56de\u4e24\u4e2a\u7ed3\u679c\u96c6\u7684\u516c\u5171\u503c\uff08\u65e0\u91cd\u590d\u9879\uff09\u3002 Oracle \u53bb\u91cd\u67e5\u8be2 Oracle \u63d0\u4f9b\u4e86\u591a\u79cd\u65b9\u6cd5\u6765\u6267\u884c\u53bb\u91cd\u67e5\u8be2\uff0c\u5373\u4ece\u7ed3\u679c\u96c6\u4e2d\u5220\u9664\u91cd\u590d\u503c\u3002 1. DISTINCT \u5173\u952e\u5b57 DISTINCT \u5173\u952e\u5b57\u662f\u6700\u7b80\u5355\u7684\u53bb\u91cd\u65b9\u6cd5\u3002\u5b83\u7528\u4e8e\u8fd4\u56de\u7ed3\u679c\u96c6\u4e2d\u6bcf\u5217\u7684\u552f\u4e00\u503c\u3002 SELECT DISTINCT column_name FROM table_name; \u767b\u5f55\u540e\u590d\u5236 2. GROUP BY \u5b50\u53e5 GROUP BY \u5b50\u53e5\u5c06\u7ed3\u679c\u96c6\u5206\u7ec4\uff0c\u5e76\u4ec5\u8fd4\u56de\u6bcf\u4e2a\u5206\u7ec4\u7684\u975e\u91cd\u590d\u503c\u3002 SELECT column_name FROM table_name GROUP BY column_name; \u767b\u5f55\u540e\u590d\u5236 3. UNIQUE \u5173\u952e\u5b57 UNIQUE \u5173\u952e\u5b57\u53ef\u7528\u4e8e\u521b\u5efa\u7d22\u5f15\uff0c\u8be5\u7d22\u5f15\u4ec5\u5305\u542b\u8868\u7684\u552f\u4e00\u884c\u3002\u67e5\u8be2\u6b64\u7c7b\u7d22\u5f15\u5c06\u81ea\u52a8\u53bb\u91cd\u3002 CREATE UNIQUE INDEX index_name ON table_name (column_name); [&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-6100","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6100","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=6100"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6100\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6100"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6100"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6100"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}