以下數據表     表名                          字段  
                character_items                  id                character_teleport               id                  character_warehouse              id                character_elf_warehouse          id                clan_data                        clan_id               clan_warehouse                     id條件:給與一個 int 參數   在以上表中的id 字段中 都找不到!  完成時間  3:30 老闆要求的:小弟先PO文求助,怕完成不了!回去研究去了,請各位大蝦幫忙!

解决方案 »

  1.   

    條件:給與一個 int 參數 在以上表中的id 字段中 都找不到!这句话什么意思??你还打的繁体,台湾的老板么?
      

  2.   

    select id from  character_items 
    union all
    select id from character_teleport
    union all
    ......这样把ID全部串起来,放到一起,你爱怎么查就可以怎么查。
         
      

  3.   

    就是以上的表都有id這個字段
    大大我錯了,這種語句不行,我講明一下  在以上的那些表中 ,隨機產生一個大於 2E的int類型的整數,但是又不能在上述所有表中的id字段存在,全部用SQL 語句來執行.就是說:  產生的隨機數,不能在上述表中的 id 字段存在,有就重新隨機,一直到不存在的,返回一個值出來!
      

  4.   

    你先用for i=1 to 10000000000000000 
    insert into tmp values (i)写入一个临时表
    查询就很简单了
    select tmp.id from tmp where not exists(select 1 from (select id from character_items 
    union all
    select id from character_teleport
    union all
    ....
    ) b where tmp.id <> b.id ) limit 1;TMP表有N多的整形数据,再去比较,取出一个。
      

  5.   

    不忽悠你。select max(id)+1 from (select id from character_items  
    union all
    select id from character_teleport
    union all
    ....
    ) b ;这样把所有ID集合起来,取最大值,然后+1,肯定就没问题了。
      

  6.   

    数据表中的 id 字段是 int 型的 现在主要是 注册的 资料要超过 int 的上限了,  然后新增资料 又是ID+1上去,肯定不是行了,所有想--把之前有删除掉的一些数据库的ID 利用起来,现在的解决问题,要不数据库的内容重新排序(——我不会排序,),要不就是改 字段成 long型,项目中用到的都换,(不适合,会影响速度)烦呢,请大大们帮忙! 
      

  7.   


    mysql> select * from a1;
    +----+-------+
    | id | title |
    +----+-------+
    |  1 | 1     |
    | 10 | 1     |
    | 20 | 2     |
    +----+-------+
    3 rows in set (0.00 sec)mysql> select id+1 from a1 a where not exists(select id from a1 b where a.id>b.i
    d);
    +------+
    | id+1 |
    +------+
    |    2 |
    +------+
    1 row in set (0.00 sec)mysql>是要求这样的结果么?