为简化问题,做如下表述:
表 temp 里面有3个字段:id,x,y
1 x1 ?
2 x1 ?
3 x1 ?
4 x1 ?
5 x1 ?这5条记录的x1 完全一样,现在需要根据x1来一个update,执行效果是
1 x1 y1
2 x1 y1+1
3 x2 y1+2
4 x2 y1+3
5 x2 y1+4请问该怎么写...

解决方案 »

  1.   

    try:update tmp set y=y1 where id in
    (select id from tmp where x='x1' order by id limit 0,1);update tmp set x='x2',y=y1+1 where id in
    (select id from tmp where x='x1' order by id limit 1,2);update tmp set x='x2',y=y1+2 where id in
    (select id from tmp where x='x1' order by id limit 2,3);update tmp set x='x2',y=y1+3 where id in
    (select id from tmp where x='x1' order by id limit 3,4);update tmp set x='x2',y=y1+4 where id in
    (select id from tmp where x='x1' order by id limit 4,5);
      

  2.   

    1 x1 y1
    2 x1 y1+1
    3 x2 y1+2
    4 x2 y1+3
    5 x2 y1+4x1,x2和y1加几有什么关系?y1加就是和当前位置有关??