可以说我有这些专栏
uniqueID|Money|Quantity|MoneyOrder|QuantityOrder 1|23|12|| 2|11|9|| 3|99|100||
我想要做的就是更新MoneyOrder和QuantityOrder基于价值ORDER BY。
MoneyOrder
QuantityOrder
ORDER BY
因此结果将是:
uniqueID|Money|Quantity|MoneyOrder|QuantityOrder 1|23|12|2|1 2|11|90|1|2 3|99|100|3|3
我希望更新操作像标识列一样,而实际上不使其成为标识列。我知道我可以按“ x”排序,结果就是顺序,但是我想生成一个报告,在这里可以逐行查看项目。
这样的事情可能update mytable set Moneyorder = 'imnotsure' order by MoneyOrder asc吗?
update mytable set Moneyorder = 'imnotsure' order by MoneyOrder asc
SET @rownumber = 0; update mytable set Moneyorder = (@rownumber:=@rownumber+1) order by MoneyOrder asc
或在单个查询中进行尝试
update mytable target join ( select id, (@rownumber := @rownumber + 1) as rownum from mytable cross join (select @rownumber := 0) r order by MoneyOrder asc ) source on target.id = source.id set Moneyorder = rownum