mysql uodate 报错 You can't specify target table '**' for update in FROM clause
You can't specify target table 'sc' for update in FROM clause
背景:把“sc”表中“叶平”老师教的课的成绩都更改为此课程的平均成绩;
上面的sql是我写的,执行就报这个错,这个原因说的是 不能从自己表里查数据再更新自己
解决方法:嵌套一层中间表
update sc set sc.score = (select t1.score from (select avg(sc1.score) score from sc sc1 where sc1.c_id=(select course.c_id from teacher,course where course.t_id=teacher.t_id and tname='叶平')) t1) where sc.c_id = (select course.c_id from teacher,course where course.t_id=teacher.t_id and tname='叶平');
这种问题仅存在于mysql中,在Oracle中是不存在的,因此在此打个mark 以防下次又忘记了