mysql, 一个表里有 10条记录,有一个rowNum列,记录的是行号,
0
1

9
如果把第3,5,7条记录删掉, 我希望删完之后能这样
0
1
2
3
4
5
6而不是
0
1
3
5
7
8
9请问咋整。

解决方案 »

  1.   

    如果是这样,其实不建议保留这个行号。有些冗余了。你可以根据下面贴子中的方法动态生成行号。http://blog.csdn.net/ACMAIN_CHM/archive/2009/04/20/4095531.aspx
    MySQL中的ROWNUM的实现
      

  2.   

    如果是:
    1、 可以用JOIN实现2、用变量累加得到行号
      

  3.   

    如果一这要更新这个字段可以。mysql> select * from tx;
    +----+
    | id |
    +----+
    |  0 |
    |  1 |
    |  2 |
    |  4 |
    |  6 |
    |  8 |
    |  9 |
    +----+
    7 rows in set (0.00 sec)mysql> update tx t1,
        -> (select id,(select count(*) from tx where id<t.id) as newid from tx t) t2
        -> set t1.id=t2.newid
        -> where t1.id=t2.id;
    Query OK, 4 rows affected (0.06 sec)
    Rows matched: 7  Changed: 4  Warnings: 0mysql> select * from tx;
    +----+
    | id |
    +----+
    |  0 |
    |  1 |
    |  2 |
    |  3 |
    |  4 |
    |  5 |
    |  6 |
    +----+
    7 rows in set (0.00 sec)mysql>
      

  4.   

    set @ee=-1;
    select id,@ee:=@ee+1 from ttqorselect a.id,count(b.id) from ttq a 
    left join ttq b on a.id>b.id
    group by a.id
      

  5.   

    update t1 a1 inner join
    (select a.id,count(b.id) as id1 from ttq a 
    left join ttq b on a.id>b.id 
    group by a.id) b1
    set a1.id=b1.id1
    where a1.id=b1.id