比如有个自增列c1,现在最大值10万,想要用一条语句查询出所有被删除掉c1的值。

解决方案 »

  1.   

    select id-1 from table1 a where not exists (select 1 from table1 where id+1=a.id
      

  2.   

    得用一个辅助表tb,ID,1-10W.
    然后select id from tb where id not in(select id from tb1);
      

  3.   

    狼的不正确
    我的数据
    tid
    1
    2
    3
    5
    10
    14
    15
    16
    17
    18
    19
    20
    21
    22
    24用狼给出的语句结果是
    tid-1
    0
    4
    9
    13
    23
      

  4.   

    貌似一句话搞不定,需要些个循环挨个判断declare count int
    set count =1
    whiel count<100000 do
      if not exists(select 1 from tb where id=count)
        insert into temptable
      set count=count + 1
    end whileselect * from temptable
      

  5.   

    declare count int
    set count =1
    while count<max(tid) do
      if not exists(select 1 from pw_threads where tid=count)
      insert into temptable
      set count=count + 1
    end whileselect * from temptable多行语句只是语法错误,mysql如何执行多行语句啊。
    我知道mssql是用;而mysql不清楚。