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

解决方案 »

  1.   

    select (cast(id as int)-1)/2 GRP, cast(id as int)%2 ITEM, id  INTO #T From TableSelect A.ID1,B.ID2 From 
    (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
      

  2.   

    select A.id id1, B.id id2 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
      

  3.   

    如果id的内容为下面的样式呢
    id
    01-02
    01-03
    01-04
    01-05
    我想要的是通用的方法。
      

  4.   

    select identity(int,1,1) AS a, id into #temp from table1 order by id
    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