Home > database >  Self-study of SQL server, consult: why update statement error?
Self-study of SQL server, consult: why update statement error?

Time:03-23

Such as: self-study SQL server, according to the select statement. Write the update statement, why select statement is correct, the correct update statement?
Select *
The from SC inner join (select c #, AVG (Score) Score_avg from SC
Where c # (in the select c # from the Teacher, course the where course. T#.=the Teacher T# and the Teacher. The Tname='Ye Ping')
Group by c #) av
On the av.=sc c #. C #

The update SC inner join (select c #, AVG (Score) Score_avg from SC
Where c # (in the select c # from the Teacher, course the where course. T#.=the Teacher T# and the Teacher. The Tname='Ye Ping')
Group by c #) av
On the av.=sc c #. C #
The set of SC. Score=av. Score_avg

CodePudding user response:

Don't always think about why his error, first to see what is right,

Behind the update can only meet specific table name or alias,
The set can only update shortly.
 
the UPDATE SCThe SET of SC. Score=av. Score_avg
The FROM SC
INNER JOIN (
SELECT c #,
AVG (Score) Score_avg
The FROM SC
WHERE c # (SELECT IN c #
FROM the Teacher,
Course
WHERE Course. T#=the Teacher. T#
AND the Teacher. Tname='Ye Ping')
GROUP BY
C #
) the av
ON the av.=sc c #. C #
  • Related