我有以下A列和B列,并希望添加一个额外的列C,以便将A列中的重复值标识为' DUP'。
答案 0 :(得分:2)
使用带有case
表达式的窗口函数:
select *,
(case when count(*) over (partition by colA) > 1
then 'Duplicate' else 'Single' end) as Dup
from table t;
答案 1 :(得分:0)
首先,您创建新列c
:
alter table my_table add c varchar(10);
然后,仅更新重复行的值:
update my_table set c = 'DUP'
where a in (
select a from my_table group by a having count(*) > 1
);