Oracle四种去重方式

Oracle四种去重方式文章介绍了在 SQL 中进行数据去重的四种常见方法 使用 DISTINCT 关键字 通过 GROUPBY 聚合 利用 ROWID 伪列结合子查询 以及应用窗口函数 row number over

大家好,欢迎来到IT知识分享网。

去重

1.distinct去重

select distinct name,age from test

2.group by 去重

select name,age from test group by name,age;

3.rowid(伪列去重)如果 step_id 也要要求去重就把条件加上去,如果不需要去重则不加

select sfc_no,step_id from AAA_HC t1 where t1.rowid in (select min(rowid) from AAA_HC t2 where t1.sfc_no=t2.sfc_no --and t1.step_id=t2.step_id );

4.窗口函数row_number () over() 去重  如果 step_id 也要要求去重就把条件加上去,如果不需要去重则不加

select t.sfc_no ,t.step_id from (select row_number() over(partition by sfc_no --,step_id order by step_id) rank,AAA_HC.* from AAA_HC)t where t.rank = 1;

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://haidsoft.com/116498.html

(0)
上一篇 2025-11-28 15:33
下一篇 2025-11-28 16:00

相关推荐

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注微信