注意:id不是PK
查询将在php中完成;
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. for($x=0;$x<num_rows;$x++){
update tbl_name set tblname = @newvalues where id=x;
}
问题:我可以获得@newvalues的所有行将其值存储在名为“ID”的列上,即使它只是来自“选择查询”的变量吗?因为此刻我只能得到它的最后一个值5.我将使用php和mysql是我的数据库。
@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(not a primary key).
有什么建议吗?