[英]How do I update a table with fields selected from another table?
Although there are many questions similar to this, such as " Updating a record from another table ", but i could not get this working. 尽管有许多与此类似的问题,例如“ 从另一个表更新记录 ”,但是我无法使它正常工作。
I have a query that selects and updates table sem_stdexamfinresmark
. 我有一个查询,用于选择和更新表
sem_stdexamfinresmark
。 The select subquery returns multiple rows of data whose size may not be equal to the table being updated, but the update is now working. select子查询返回多行数据,其大小可能不等于正在更新的表,但是更新现在可以进行了。
The query looks like : 查询看起来像:
update sem_stdexamfinresmark sr,
(select
se.currsession,
str.studentid,
str.classid,
str.subjectid,
str.aggScore*(select gbtp.percentage from gb_termpercentage gbtp where gbtp.termname = se.examtype)/100 as aggPer,
str.aggGrade
from
sem_stdexamtermresr str,
sem_exam se
where
str.examid=se.examid and
se.examtype = 'Second Term' and
se.currsession =1 and classid='8'
) s
set
sr.SecondTermMark = s.aggPer and
sr.SecondTermGrade = s.aggGrade
where
sr.studentid=s.studentid and
sr.subjectid=s.subjectid and
s.currsession = s.currsession and
sr.classid='8';
EDIT: 编辑:
update sem_stdexamfinresmark
set
sr.SecondTermMark = s.aggPer and
sr.SecondTermGrade = s.aggGrade
from
(select
se.currsession,
str.studentid,
str.classid,
str.subjectid,
str.aggScore*(select gbtp.percentage from gb_termpercentage gbtp where gbtp.termname = se.examtype)/100 as aggPer,
str.aggGrade
from
sem_stdexamtermresr str,
sem_exam se
where
str.examid=se.examid and
se.examtype = 'Second Term' and
se.currsession = 1 and classid='8'
) s
where
sr.studentid=s.studentid and
sr.subjectid=s.subjectid and
s.currsession =1 and
sr.classid='8';
select * from sem_exam;
update sem_exam set currsession =1;
try something that looks more like: 尝试一些看起来更像的东西:
update foo
set col = bar.col
from bar
where ...
这就是当一个人失去睡眠时发生的事情:(我只是在这里犯了一个愚蠢的错误,并添加了“和”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.