0

尝试运行以下查询:

UPDATE task_schedule
JOIN tasks ON (tasks.taskid=task_schedule.taskid)
SET task_schedule.user_position = @counter := @counter + 1
WHERE tasks.userid_owner = 6
ORDER BY task_schedule.product_position asc, task_schedule.productid asc

但是得到错误使用 UPDATE 和 ORDER BY错误。

无论如何我可以解决这个问题?

4

1 回答 1

2

ORDER BY上的多表语法是不允许的UPDATE。这是修复查询的一种方法:

UPDATE task_schedule
SET task_schedule.user_position = @counter := @counter + 1
WHERE exists (select 1
              from tasks t
              where t.userid_owner = 6 and
                    t.taskid = task_schedule.taskid
             )
ORDER BY task_schedule.product_position asc, task_schedule.productid asc
于 2013-09-03T10:47:52.837 回答