oracle 中,对指定的列值重复,只显示第一个值,其余列保持不变,要如何实现?高人赐教
表字段:ABCD123412343344abababcdabcd对指定的列(如:A,B)进行处理,有重复的列值,只显示第一个的值,其余为空(“”)结果如下:表字段:ABC...
表字段: A B C D
1 2 3 4
1 2 3 4
3 3 4 4
a b a b
a b c d
a b c d
对指定的列(如:A,B)进行处理,有重复的列值,只显示第一个的值,其余为空(“”)
结果如下:
表字段: A B C D
1 2 3 4
3 4
3 3 4 4
a b a b
c d
c d 展开
1 2 3 4
1 2 3 4
3 3 4 4
a b a b
a b c d
a b c d
对指定的列(如:A,B)进行处理,有重复的列值,只显示第一个的值,其余为空(“”)
结果如下:
表字段: A B C D
1 2 3 4
3 4
3 3 4 4
a b a b
c d
c d 展开
展开全部
通过脚本来实现,谈肢比较直观容含乱世易理解。
declare
v_a char(1):='0';
v_b char(1):='0';
v_aa char(1):='';
v_bb char(1):='';
cursor c1 is select A,B,C,D from TAB order by A,B,C,D;
v c1%rowtype;
begin
open c1;
loop
fetch c1 into v;
exit when c1%notfound;
if v_a=v.a then v_aa:='陪睁';
else v_a:=v.a; v_aa:=v.a;
end if;
if v_b=v.b then v_bb:='';
else v_b:=v.b; v_bb:=v.b;
end if;
dbms_output.put_line(v_aa||' '||v_bb||' '||v.c||' '||v.d);
end loop;
close c1;
end;
declare
v_a char(1):='0';
v_b char(1):='0';
v_aa char(1):='';
v_bb char(1):='';
cursor c1 is select A,B,C,D from TAB order by A,B,C,D;
v c1%rowtype;
begin
open c1;
loop
fetch c1 into v;
exit when c1%notfound;
if v_a=v.a then v_aa:='陪睁';
else v_a:=v.a; v_aa:=v.a;
end if;
if v_b=v.b then v_bb:='';
else v_b:=v.b; v_bb:=v.b;
end if;
dbms_output.put_line(v_aa||' '||v_bb||' '||v.c||' '||v.d);
end loop;
close c1;
end;
展开全部
表名我为其命名为:a1
create view v_a1 as select rownum as rn,a1.* from a1;
select T.a,T.b,T.c,T.d
from (
select rn,a,b,c,d
from v_a1
where (rn,a,b) in (select min(rn) as rn,a,b
from v_a1
group by a,b)
union all
select rn,'袭敬' as a,'戚禅辩'高缺 as b,c,d
from v_a1 v1
where (rn,a,b) not in (select min(rn) as rn,a,b
from v_a1
group by a,b)
) T
order by T.rn;
create view v_a1 as select rownum as rn,a1.* from a1;
select T.a,T.b,T.c,T.d
from (
select rn,a,b,c,d
from v_a1
where (rn,a,b) in (select min(rn) as rn,a,b
from v_a1
group by a,b)
union all
select rn,'袭敬' as a,'戚禅辩'高缺 as b,c,d
from v_a1 v1
where (rn,a,b) not in (select min(rn) as rn,a,b
from v_a1
group by a,b)
) T
order by T.rn;
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询