declare @tb table
(
testID int,
testID1 int
)
insert @tb
select 1,2 union all
select 1,2 union all
select 2,2 union all
select 1,2 union all
select 3,3 union all
select 4,5 union all
select 4,6
select identity(int,1,1) as ID
,*
into #
from @tb
--查询
select testID
,testID1
,(select count(1)
from #
where testID=t.testID
and testID1=t.testID1
and ID<=t.ID
) as [order]
from # t
order by testID,testID1,ID
--查询
select testID
,testID1
,(select count(1)
from #
where testID=t.testID
and testID1=t.testID
and ID<=t.ID
) as [order]
from # t
order by testID,testID1,ID