日期:2014-05-19  浏览次数:20387 次

求一SQL语句?
我想找一个表中如果发现其有两笔以上相同的记录时,就把把它的某个字段更新(比如MD045)!!
此sql语句如何写呀?

------解决方案--------------------
第一步、修改字段,字段值递增的语句

declare @index int

set @index = 1
update table set MD045 = @index,@index = @index+1 where ...

第二步找到符合条件的语句,

decare @aa nvarchar(1000)
select select @aa = min(f1) from yourtable group by f1,f2,f3... having count(*)> =2

select id from yourtable where f1=@aa

合在一起就是


declare @index int

set @index = 1 --这里还要改一下。
update table set MD045 = @index,@index = @index+1 where

id in (

select id from yourtable where f1=

(select select min(f1) from yourtable group by f1,f2,f3... having count(*)> =2)

)


没有测试不知道对不对。