22,299
社区成员




select id,seq,(select count(distinct id) from (select * from du where T_Type = 7 and ifparent =0 and PID = 0 order by seq) a where a.seq<=b.seq) as rowno from (select * from du where T_Type = 7 and ifparent =0 and PID = 0 order by seq) b
if not object_id(N'Tempdb..#tab') is null
drop table #tab
Go
Create table #tab([name] nvarchar(21),[qname] nvarchar(24),[heji] int)
Insert #tab
select N'A',N'永久',10 union all
select N'A',N'12個月',20 union all
select N'A',N'6個月',30 union all
select N'A',N'3個月',40 union all
select N'A',N'永久',15 union all
select N'A',N'12個月',6 union all
select N'A',N'6個月',5 union all
select N'B',N'永久',20 union all
select N'B',N'12個月',30 union all
select N'B',N'6個月',40 union all
select N'B',N'3個月',50 union all
select N'B',N'永久',1
Go
select * from #tab
Select IDENTITY(INT,1,1) AS 序号,* into #a from #tab
select * from #a
drop table #tab
drop table #a
update du set seq=a.rowno from (select * from du where T_Type = 7 and ifparent =0 and PID = 0 order by seq) as a
where a.id=du.id