目标表不可更新错误

时间:2013-04-14 21:48:58

标签: mysql insert-update

我需要运行此查询:

UPDATE (
   SELECT r.* 
   FROM booked r 
   INNER JOIN (
      SELECT a.st_code as from_t
           , b.st_code as to_t 
      FROM `stops_at` a 
      CROSS JOIN `stops_at` b 
      WHERE (a.stop_no < b.stop_no) 
        and (a.train_no = b.train_no) 
        and (a.train_no = '11280')
      ) new 
   ON (r.st_from = new.from_t) 
     and (r.st_to = new.to_t)
     and r.date = '2013-04-16'
   ) temp 
SET temp.seat_ac = temp.seat_ac-5

但在执行时会出错:

#1288 - UPDATE的目标表temp不可更新

任何解决方案?

1 个答案:

答案 0 :(得分:2)

我认为您的UPDATE语法不正确。看看是否有效:

UPDATE booked r
INNER JOIN (
   SELECT a.st_code as from_t
        , b.st_code as to_t 
   FROM `stops_at` a 
   CROSS JOIN `stops_at` b 
   WHERE (a.stop_no < b.stop_no) 
     and (a.train_no = b.train_no) 
     and (a.train_no = '11280')
   ) new 
ON r.st_from = new.from_t 
  and r.st_to = new.to_t
  and r.date = '2013-04-16' 

SET r.seat_ac = r.seat_ac-5