SQL语句如何更改重复的记录
更改Table中字段refinv里的内容,有重复的内容在后面加数字,后面的数字是有序的。
原表:
id refinv price date
----------- -------------------- ---------------------- -----------------------
1 060108CS 2 2006-12-04 15:55:56.680
2 060109CS 3.5 2006-12-04 15:55:56.680
3 060109CS 5 2006-12-04 15:55:56.680
4 060110CS 6 2006-12-04 15:55:56.680
5 060110CS 9 2006-12-04 15:55:56.680
6 060110CS 8 2006-12-04 15:55:56.680
更新后的新表:
id refinv price date
----------- -------------------- ---------------------- -----------------------
1 060108CS 2 2006-12-04 15:57:04.290
2 060109CS-1 3.5 2006-12-04 15:57:04.290
3 060109CS-2 5 2006-12-04 15:57:04.290
4 060110CS-1 6 2006-12-04 15:57:04.290
5 060110CS-2 9 2006-12-04 15:57:04.290
6 060110CS-3 8 2006-12-04 15:57:04.290
SQL语句:
create table #tmp(id int identity(1,1) primary key,
refinv varchar(20),price float,date datetime DEFAULT (getdate())
)
insert into #tmp(refinv,price)
select '060108CS','2'
union all
select '060109CS','3.5'
union all
select '060109CS','5'
union all
select '060110CS','6'
union all
select '060110CS','9'
union all
select '060110CS','8'