我做的姿势
select idx from table where number = 1;
并且此选择返回10行(例如),并且我想将这10行的idx列从0更新为9。我该怎么做?
更新:
这是一个查询
/ orderID / lineID / q / idx /
/ 1 / 1 / 1 / 0 /
/ 1 / 2 / 1 / 1 /
/ 1 / 3 / 1 / 2 /
/ 2 / 4 / 1 / null /
/ 2 / 5 / 1 / null /
/ 2 / 6 / 1 / null /
/ 3 / 7 / 1 / null /
/ 3 / 8 / 1 / null /
我想替换为idx的空值,如下所示:
/ orderID / lineID / q / idx /
/ 1 / 1 / 1 / 0 /
/ 1 / 2 / 1 / 1 /
/ 1 / 3 / 1 / 2 /
/ 2 / 4 / 1 / 0 /
/ 2 / 5 / 1 / 1 /
/ 2 / 6 / 1 / 2 /
/ 3 / 7 / 1 / 0 /
/ 3 / 8 / 1 / 1 /
最佳答案
对于更新,您可以使用带有语法的更新查询
> UPDATE [LOW_PRIORITY] [IGNORE] table_reference
> SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...
> [WHERE where_condition]
> [ORDER BY ...]
> [LIMIT row_count]
Refrence
就你而言
update table SET idx=9 where number = 1;
关于mysql - 如何在MySQL中进行迭代?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27628197/