--如果是先后次序,索性分别写进2个带自增列的临时表,用自增列来结合好了
--如下
select id=identity(int,1,1),* into #1 from A
select id=identity(int,1,1),* into #2 from B
select idA,idB
from #1 A inner join #2 B
on A.id=B.id
select
m.idA,n.idB
from
(select t.*,(select count(*) from A表 where task_id=t.task_id and tag_id=t.tag_id and idA<=t.idA) as nid from A表 t) m,
(select t.*,(select count(*) from B表 where task_id=t.task_id and tag_id=t.tag_id and idB<=t.idB) as nid from B表 t) n
where
m.task_id=n.task_id and m.tag_id=n.tag_id and m.nid=n.nid