insert @tb
select '00', 80 union all
select '01', 80 union all
select '02', 80 union all
select '03', 17 union all
select '04', 17 union all
select '05', 56 union all
select '06', 56
select id,
[value]=(case when exists(select 1 from @tb where value=t.value and id>t.id)
then ''
else convert(varchar,value)
end
)
from @tb t order by id
--结果
/*
id value
---------- ------------------------------
00
01
02 80
03
04 17
05
06 56
--建立测试环境
Create Table TEST
(ID Varchar(50),
Score Int)
Insert TEST Values('00', 80)
Insert TEST Values('01', 80)
Insert TEST Values('02', 80)
Insert TEST Values('03', 17)
Insert TEST Values('04', 17)
Insert TEST Values('05', 56)
Insert TEST Values('06', 56)
--测试
Select
ID,(
Case When Exists (Select 1 from TEST Where Score=A.Score And Cast(ID As Int)=Cast (A.ID As Int)+1 ) Then Null Else Score End ) Score
from TEST A
--删除测试环境
Drop Table TEST
--结果
/*
ID Score
00 NULL
01 NULL
02 80
03 NULL
04 17
05 NULL
06 56
*/
create table ta(id varchar(10), value int)
go
insert ta select '00', 80 union all select '01', 80
union all select '02', 80 union all select '03', 17
union all select '04', 17 union all select '05', 56
union all select '06', 56
--update
update ta
set value=null
where exists( select 1
from ta as tt
where ta.value=tt.value
and ta.id<tt.id)
select * from ta
--清除
drop table ta