弱问sql简单问题
我想从表中删除所有不同value的行,但是具有相同value的行只删除第一行,请问如何操作?
[解决办法]
create table bs(value varchar(1))insert into bsselect 'a' union allselect 'b' union allselect 'b' union allselect 'c' union allselect 'c' union allselect 'c'select value from bsvalue-----abbccc-- 执行一次操作后,表变成{b,c,c};with t as( select row_number() over(partition by value order by (select 0)) rn from bs)delete from t where rn=1select value from bs value-----bcc-- 再执行一次,变成{c};with t as( select row_number() over(partition by value order by (select 0)) rn from bs)delete from t where rn=1select value from bs value-----c