谁能帮我看这段SQL语句:---for W02 ---script 1 alter table W02 add ID int identity(1,1); -----script

2025-04-17 09:18:51
推荐回答(1个)
回答1:

--W01中每组GB011的最小ID放到表#TEMP中
select min(ID) as ID into #TEMP from W01 Group by GB011;

--修改W01,将W01中有但是#TEMP中没有的ID,GB011改为null
update W01
set GB011= null
where ID not in (select ID from #TEMP);

--删除表#TEMP
drop table #TEMP;

--删除列ID
alter table W01 drop column ID;

其实就是把每一组GB011中非最小ID的行GB011改为空