insert into hylx(hylxid)
select max(hylxid)+1 as hylxid from hylx where  hylxid<99

解决方案 »

  1.   

    这样可以,但是插入的记录其他字段没有值就只有一个hylxid,我还有一些字段的值没有插入,怎么办呢?我的表有这些字段:hylxid   hylx   type  keyinsert into hylx(hylxid) select max(hylxid)+1 as hylxid from hylx where  hylxid<99
    这个执行插入之后hylxid   hylx   type  key
    11       aa      bb    cc
    12       null    null  null  --->这是刚才插入的。但是我hylx   type  key都分别还有值。
      

  2.   

    insert into hylx(hylxid,hylx,type,key) 
    select max(hylxid)+1 as hylxid,hylx的值,type的值,key的值 from hylx where  hylxid<99注意:你这样作在多用户并发的时候会出问题的,使用最大值,建议你要加锁
      

  3.   

    可以先查出hylxid加1,放到一个变量t_hyxid中,再执行插入语句.
    select max(hylxid)+1 into t_hylxid from hylx where hylxid<99;
    insert into hylx(hylxid,hylx,type,key) values(t_hylxid,hylx的值,type的值,key的值);