去重
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 t1where 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_idorder by step_id) rank,AAA_HC.* from AAA_HC)twhere t.rank = 1;
row_number() over(partition by SFC_NO order by CREATE_DATE desc) rn
为新增一个名为rn的排名的列,partition by 列名(需要分组的列) order by 列名(需要排名的列)
结果
SFC_NO CREATE_DATE rn
aaa 2022-09-22 1
aaa 2022-09-21 2
aaa 2022-09-20 3
bbb 2022-09-22 1
bbb 2022-09-21 2
bbb 2022-09-20 3