我想order by
在这个查询中使用:
update mytable cross join (select @i := 0) params set mydate = mydate + interval 10 * (@i := @i + 1) hour;
我的参考是来自这个问题,因为那个问题让我说我想命令PID下降,
update mytable cross join (select @i := 0) params set mydate = mydate + interval 10 * (@i := @i + 1) hour order by PID desc;
但是我得到了那个问题 ERROR 1221 (HY000): Incorrect usage of UPDATE and ORDER BY
原始查询工作正常,但我无法使用order by
它.
像下面这样的东西可能会:
UPDATE mytable MT INNER JOIN ( SELECT *, @i := @i + 1 AS paramNumber FROM mytable cross join(select @i := 0) params ORDER BY PID DESC ) AS t ON MT.PID = t.PID SET MT.mydate = MT.mydate + INTERVAL (10 * (t.paramNumber)) HOUR
14.2.11 UPDATE Syntax
单表语法:
UPDATE [LOW_PRIORITY] [IGNORE] table_reference SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ... [WHERE where_condition] [ORDER BY ...] [LIMIT row_count]多表语法:
UPDATE [LOW_PRIORITY] [IGNORE] table_references SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ... [WHERE where_condition]对于多表语法,UPDATE更新table_references中指定的满足条件的每个表中的行.每个匹配的行都会更新一次,即使它与条件多次匹配也是如此.对于多表语法,不能使用ORDER BY和LIMIT.