日期:2014-05-17  浏览次数:20413 次

一个测试题不会做,求Help..
有表 Student 结构和数据如下:
编号    总分数
ID SCORE 
1 50
2 30
3 20
4 50
5 10

表 ScoreB (某科目分数)
Student.ID FK   科目的分数
StudentID SOCRE
1 10
2 30
3 20
4 20

怎么快速的将ScoreB中的SCORE加到student表对应的项中
比如说执行后。ScoreB.StudentID为1的分数(10)加到Student.ID为1的里面,并且更新Student

我用的是游标,有好几万条数据,更新频繁的话 sqlserver.exe占很大的内存。所以看大家有没有更好的办法。。

------解决方案--------------------
update Student set SROE=SROE+(select SROE_2 from Student_2 where id=id_2) 
where id in(select id_2 from Student_2)
------解决方案--------------------
update student set score=score+b.score from ScoreB b
where student.id=b.id