开发者

MySQL UPDATE values with sequence 1,2,3,

I have table with po开发者_开发技巧sition atribute 'posit' with unknown values (in my example '0') and I want to UPDATE it to 1,2,3, ...

BEFORE:

 _______________
| title | posit |
|---------------|
|  test |   0   |
|-------|-------|
|  test |   0   |
|-------|-------|
|  test |   0   |
|-------|-------|
|  test |   0   |
'---------------'

AFTER:

 _______________
| title | posit |
|---------------|
|  test |   1   |
|-------|-------|
|  test |   2   |
|-------|-------|
|  test |   3   |
|-------|-------|
|  test |   4   |
'---------------'

Something like this

UPDATE myTable 
SET posit = last_updated_value() + 1 
WHERE title='test';

Is there any way to do it by SQL command? Note that 'posit' is not auto increment. I have only PHP solution.

Thanks Henry


You have mysql as a tag, so with that you could use a user defined variable. Something like this:

SET @incr = 0;
SELECT @incr:=@incr+1 FROM DUAL;

See http://dev.mysql.com/doc/refman/5.0/en/user-variables.html for more details.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜