各位高人我现在的数据库中设定了一个字段自增长(ver)。但是出现的如下的增长结果:
id    ver      name         city
001    1       andy          dl
001    2       sam           bj 
002    3       candy         sh
002    4       bob           wh
我如何设定才能做成如下结果呢:
id    ver      name         city
001    1       andy          dl
001    2       sam           bj 
002    1       candy         sh
002    2       bob           wh
是不是这个无法再数据库中设定实现?

解决方案 »

  1.   

    应该不行吧,这样的字段,可以在select的时候计算出来。看看有没有人知道怎么设置吧。
      

  2.   

    mysql> create table auto (id int not null ,ver int auto_increment,primary key(id
    ,ver))engine =myisam
        -> ;
    Query OK, 0 rows affected (0.03 sec)mysql> insert into auto(id) values(1),(1),(2),(2);
    Query OK, 4 rows affected (0.00 sec)
    Records: 4  Duplicates: 0  Warnings: 0mysql> select * from auto;
    +----+-----+
    | id | ver |
    +----+-----+
    |  1 |   1 |
    |  1 |   2 |
    |  2 |   1 |
    |  2 |   2 |
    +----+-----+
    4 rows in set (0.00 sec)
    只限于myisam
      

  3.   

    不能..auto_increment 只能用于连续增长 不能区间增长自己写个触发器实现吧
      

  4.   

    楼主的存储引擎是什么?myisam的话 2楼的不是实现了?
      

  5.   

    为什么只限于myisam?可否说明原因
      

  6.   

    myisam好像就不能用事务处理了。可我在插表的时候需要进行事务处理。多表插入一次提交
      

  7.   

    高人们能不能帮我把下边这个SQL修正一下?总是报错。完后马上结贴insert into t_wirelesslan_rrk (wirelessno, ver) 
    values ('00000001', (select ifnull(max(ver),0)+1 as max_ver from t_wirelesslan_rrk where wirelessno='00000001'))