34,870
社区成员




insert into score(sno,sname,score)
select sno,sname,(select avg(score) from sc where sc.SNo=student.SNo)
from student
select a.sno,a.sname,avg(b.score) score into #tb
from student a join SC b on a.sno = b.sno
--where ...
group by a.sno,a.sname
insert into score(sno,sname,score)
select *
from #tb t
where not exists (select 1 from score where sno = t.sno)
update a
set a.score = b.score
from score a join #tb b on a.sno = b.sno
drop table #tb
INSERT INTO SCORE(CLASS,SName,SCORE)
SELECT S.CLASS,S.SName,AVG(C.SCORE) FROM Student S JOIN SC C
ON S.SNO=C.SNO
--WHERE
GROUP BY S.SName,S.CLASS
insert into score(sno,sname,score)
select a.sno,a.sname,avg(b.score)
from student a join SC b on a.sno = b.sno
--where ...
group by a.sno,a.sname
with t as
(select avg(score) as score,sno from sc group by sno)
insert into score(sno,sname,score)
select student.sno,student.sname,t.score from t join on Student on t.sno=Student.sno