MySQL UPDATE 值序列为 1,2,3,

发布于 2024-09-25 03:20:18 字数 722 浏览 1 评论 0原文

我有一个带有未知值的位置属性“posit”的表(在我的示例中为“0”),我想将其更新为 1,2,3, ...

之前:

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

之后:

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

类似这样的事情

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

有没有办法做到 这一点通过SQL命令?请注意,“posit”不是自动递增的。我只有 PHP 解决方案。

谢谢 亨利

I have table with position 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

﹉夏雨初晴づ 2024-10-02 03:20:18

您将 mysql 作为标签,因此您可以使用用户定义的变量。像这样的东西:

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

请参阅 http://dev.mysql.com/ doc/refman/5.0/en/user-variables.html 了解更多详细信息。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文