目标表不可更新错误

o8x7eapl  于 2021-06-24  发布在  Mysql
关注(0)|答案(1)|浏览(364)

我需要运行此查询:

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更新的目标表temp不可更新。

有什么解决办法吗?

slsn1g29

slsn1g291#

我认为你的 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

相关问题