错误代码:
update sc set grade = grade * 1.1where sno in(select sno from sc group by sno having avg(grade)>=75);
报错详情
You can't specify target table 'sc' for update in FROM clause
该报错意思如下:不能在update更新一张表的时候,同时在子查询中使用(查询 / 筛选)该表。
解决方法
设立双层子查询,让程序的执行逻辑产生先后顺序,以便正常运行,写法如下:
update sc set grade = grade * 1.1where sno in(select * from (select sno from sc group by sno having avg(grade)>=75)as temp);
来源地址:https://blog.csdn.net/m0_67470729/article/details/128101326