【发布时间】:2014-03-17 15:43:55
【问题描述】:
我的想法是这样的'使用sql变量'
注意:id不是PK
1st query `select @newvalues := (id - coalesce((select sum(minus) from tbl_name t2 where t2.id < t.id), 0)) from tbl_name t;`
2nd query. `update tbl_name set ab = @newvalues;`
即使它只是一个“选择查询变量”,我可以得到所有的@newvalues 行吗?因为目前我只能得到它的最后一个值,即 5。
@newvalues ID *not Primary key
9 | -----------> 9 |
8 | -----------> 8 |
7 | -----------> 7 |
6 | -----------> 6 |
5 | -----------> 5 |
*transfer the row values of @newvalues to the column ID.
【问题讨论】:
-
请任何 cmets/ 帮助。我真的很感激
-
php专家,请帮忙。新手在这里。
-
我会推荐一个名为
superNewID的新列并运行UPDATE table set superNewID=(newID-minus) where id=id。完成此操作后,删除ID列并将superNewID重命名为ID -
你能解释一下你想在这里做什么吗?
ID是这个表的主键吗?从表面上看,这似乎是一种糟糕的方法。 -
也别再乞求了,它会让人们想删除你的问题而不是帮助你。当我看到你的 cmets 进来时,我犹豫着说什么
标签: php mysql variables for-loop sql-update