create table orders ( company varchar(10), ordernumber int ) insert into orders select ‘IBM‘,4566 union all select ‘JIS‘,4565 union all select ‘JOINY‘,4544 union all select ‘JOINY‘,4544 union all select ‘JOINY‘,4544 union all select ‘EWIRU‘,2321 union all select ‘HUIJ‘,4561 union all select ‘HUIJ‘,4561 ;with cte as ( select ROW_NUMBER() over(partition by company,ordernumber order by company,ordernumber) as ro, company,ordernumber from orders ) --删除重复数据 delete from cte where ro>1 --重新定义顺序:顺序规则自己定义了 update orders set ordernumber=1+ro from (select ROW_NUMBER() over(order by company,ordernumber) as ro from orders) a
时间: 2024-10-12 16:03:22