select A.id, B.id where table1 A, table1 B
where cast(A.id as int)= cast(B.id as int) - 1
and cast(A.id as int) % 2 = 1
and cast(B.id as int) % 2 = 0
where cast(A.id as int)= cast(B.id as int) - 1
and cast(A.id as int) % 2 = 1
and cast(B.id as int) % 2 = 0
(Select GRP,ID ID1 From #T WHERE ITEM = 1) A
FULL OUTER JOIN
(Select GRP,ID ID2 From #T WHERE ITEM = 0) B
ON A.GRP = B.GRP
ORDER BY A.GRP
where cast(A.id as int)= cast(B.id as int) - 1
and cast(A.id as int) % 2 = 1
and cast(B.id as int) % 2 = 0
id
01-02
01-03
01-04
01-05
我想要的是通用的方法。
select A.id, B.id
from (select a, id from #temp where a % 2 = 1) A
inner join (select a, id from #temp where a % 2 = 0) B
on A.a = B.a - 1