有表如下:
ID
1
2
3
5
6
8
10
13
14
15
17
19
查询出所有连续的ID:
ID
1
2
3
5
6
13
14
15

解决方案 »

  1.   

    select a.* from 表 a where exists(select 1 from 表 where ID=a.ID+1) or exists(select 1 from 表 where ID=a.ID-1)
      

  2.   

    TO: libin_ftsafe(子陌红尘:当libin告别ftsafe) ( ) 
    你的速度真快啊
    答案也很好
    呵呵……
      

  3.   

    SELECT a.ID FROM tb a
    INNER JOIN tb b
    ON ABS(a.id-b.id)=1
    ORDER BY a.ID
      

  4.   

    SELECT DISTINCT a.ID FROM tb a
    INNER JOIN tb b
    ON ABS(a.id-b.id)=1
    ORDER BY a.ID
      

  5.   

    libin_ftsafe(子陌红尘:当libin告别ftsafe)
    佩服!