create table #temp
(
 fid int,
 fkid int,
 flag int
)
insert into #temp values (1,1,null)
insert into #temp values (2,1,null)
insert into #temp values (3,2,null)
insert into #temp values (4,2,null)
insert into #temp values (5,2,null)
insert into #temp values (6,3,null)
insert into #temp values (7,3,null)

select * from #temp
drop table #temp
 
我想让fkid 为1的第一条数据 flag 为 1
我想让fkid 为2的第一条数据 flag 为 1
我想让fkid 为3的第一条数据 flag 为 1其他为0 ,求一个动态写法,fkid 不是固定的 谢谢