0	35	023249	update sc set grade = grade+5 where sno in select sno from student where ssex = 女 and gradeselect avggrade from sc 	Error Code 1093 You cant specify target table sc for update in FROM clau This error occurs because the same table "sc" is being used in both the UPDATE statement and the subquery that selects the students. MySQL does not allow updating a table and selecting from the same table in a subquery.

To fix this error, you can use a temporary table to store the student IDs and then update the "sc" table using the temporary table. Here's an example query:

CREATE TEMPORARY TABLE temp_sno
SELECT sno FROM student WHERE ssex = '女';

UPDATE sc SET grade = grade + 5
WHERE sno IN (SELECT sno FROM temp_sno) AND grade < (SELECT AVG(grade) FROM sc);

DROP TEMPORARY TABLE temp_sno;

This query first creates a temporary table "temp_sno" that stores the student IDs of female students. Then it updates the "sc" table using the student IDs from the temporary table and the average grade from the "sc" table. Finally, it drops the temporary table.

0	35	023249	update sc set grade = grade+5 where sno in select sno from student where ssex = 女 and gradeselect avggrade from sc 	Error Code 1093 You cant specify target table sc for update in FROM clau

原文地址: https://www.cveoy.top/t/topic/ds9l 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录