删除表中多余的重复记录(多个字段),只留有rowid最小的记录
delete from 表 a
where (aId,aseq) in
(select Id,seq from 表 group by Id,seq having count() > 1)
and rowid not in
(select min(rowid) from 表 group by Id,seq having count()>1)
用分析函数row_number() over (partition by order by )给记录按组编号,然后只取编号值为1的记录,应该就是你要的结果集了。
select sfrom (
select dA_ID, dA_DATE, dA_NAME, row_number() over (partition by dA_ID order by dA_DATE desc) as rowidx
from your_table d
) s
where srowidx = 1
row_number这样的分析函数,基本上现在主流的数据库都有支持(版本太旧的话是没有此功能的)。
使用以下函数即可完成:--字符串去重复字符函数
CREATE OR REPLACE FUNCTION remove_rame_string(
v_strings in varchar2
)
return varchar2
IS
v_strings1 varchar2(64) default ' ';
begin
v_strings1:=nvl(replace(rtrim(ltrim(v_strings)),' ',''),' ');
select listagg(c, '') within group(order by id2) into v_strings1
from (select distinct c,id2
from (select row_number() over(partition by ev_strings1 order by substr(ev_strings1, iterpos, 1)) rn,
substr(ev_strings1, iterpos, 1) c,1 as id2
from (select v_strings1 from dual) e,
(select rownum pos from user_tables) iter
where iterpos <= length(ev_strings1)
order by 1));
return v_strings1 ;
end remove_rame_string;
/表students
sid sname
1 aa
2 bb
3 cc
4 aa
如何写查询语句
去掉sname中重复的
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)