oracle四种常用去重方法
1、使用distinct:
<span style="font-size:18px;">SELECT DISTINCT PART_NO FROM ACT;</span>
2、使用group by:
SELECT PART_NO FROM ACT WHERE ID IN (SELECT MAX(ID) FROM ACT GROUP BY PART_NO );
3、使用rowid:
SELECT ROWID, PART_NO FROM ACT A WHERE ROWID = (SELECT MAX(ROWID) FROM ACT B WHERE A.PART_NO = B.PART_NO);
4、使用开窗函数row_number() over():
<span style="font-size:18px;">SELECT
PART_NO
FROM
(
SELECT
PART_NO, ROW_NUMBER() OVER(PARTITION BY PART_NO ORDER BY NULL) RN
FROM
ACT
)
WHERE
RN = 1</span>
实践证明:同等条件下,第四种方式使用开窗函数的效率是最高的,其次是使用distinct, 然后是使用rowid,最后是group by。但是还没得到官方证实,这有待后面学习之后补上!